This is a packaging question in Go. I have a package schema that looks like this: project | --- common_test.go | --- sub1 | | | --- file.go | --- file_test.go --- sub2 | | | | | --- file.go | --- file_test.go
common_test.go
would look like that:
package project
type Test struct {
...
}
And sub1
and sub2
would look like:
package sub1
import "project"
func SomeTest(t *testing.T) {
test := project.Test{}
...
}
The project package only contains the common_test.go
file, which defines structures that are used in both sub1/file_test.go
and sub2/file_test.go
. But if I try to trigger the test, I get the following error:no buildable Go source files in project
.
I understand that it is because common_test.go
includes the _test
suffix and because it is the only file in the project
package. But I use the suffix for the reason I don't want this file to be compiled except for test execution.
Is there a way to define test-specific common structures in a package that does not contain non-test files? What is the good practice in this case?