While writing test cases I found 2 problems:
There are 3 test files out of which one_test.go
and two_test.go
can be added to server_suites_test.go
and it runs fine. But the functions of three_point_one_test.go
cannot be added into server_suites_test.go
because _test.go
cannot be imported.
one_test.go
and two_test.go
use gRPC client object which is created by server_test.go
. Actually, server_test.go
creates a gRPC server and a client and this client is used by the other test cases. Currently three_point_one_test.go
cannot access this client. So to solve this issue I'm creating client every time this test is run.
Project Structure(incomplete BTW!)
> tree /f
Folder PATH listing for volume Windows
Volume serial number is 1C92-17A5
C:.
└───data
│ one.go
│ one_test.go
│ two.go
│ two_test.go
│ server.go
│ server_suites_test.go
│ server_test.go
│
└───three
three_point_one.go
three_point_one_test.go
server_suites_test.go
package data
import (
"testing"
"someproj/three"
)
func TesOne(t *testing.T) {
t.Run("One", testOne) //from one_test.go
}
func TestTwo(t *testing.T) {
t.Run("Two", testTwo) //from two_test.go
}
// Below code cannot be compiled -START
func TestThreePointOne(t *testing.T) {
t.Run("ThreePointOne", three.TestThreePointOne) //cannot import this function
}
// Below code cannot be compiled -END
Is there any way to add other tests present in children packages into the test suite?
Is there any way to add other tests present in children packages into the test suite?
No.
Tests are not part of the package. As you can import only whole packages and the tests are not part of it you simply cannot. And stop thinking about "child packages": There are no such things. All packages are equal and their filesystem location does not matter (except internal and vendor).