-2

I have the following architecture :

- package-a
   - a.go
   - a_test.go
- package-b
   - b.go
   - b_test.go
- package-c
   - c.go
   - c_test.go

I would like to use data initialized in a_test.go inside of b_test.go, is it possible ?

Example :

var FakeData = FakeData{ something... }

I have made my own researches and it look like it is not possible to share data across different package's tests files.

enter image description here

How to share test interfaces between Go packages?

enter image description here

https://github.com/golang/go/issues/10184


First : is my assumption correct ?

Second : do you know of any documentation that would enforce the fact ?


I have looked at https://golang.org/ref/spec but could not find anything.

Thanks

Orelsanpls
  • 22,456
  • 6
  • 42
  • 69

1 Answers1

2

I would like to use data initialized in a_test.go inside of b_test.go, is it possible ?

No, this is not possible.

is my assumption [is not possible to share data across different package's tests files] correct ?

Yes.

do you know of any documentation that would enforce the fact ?

Yes. That is how testing works. Running go test will include the _test.go files from the package under test and produce a synthetic main package which can be compiled and linked to an executable which then is executed. No other _test.go files are included ever into that test binary. There is no documentation that explains this "No other!" fact, but this is implicit from the "only the test files from the current".

Provide a "real" package (probably an internal one) providing this test data from non- _test.go files.

Volker
  • 40,468
  • 7
  • 81
  • 87