There are a few test cases I want to run for which there is a need to start a GRPC mock server. I am using gomock library for this. To start the server, I have to pass a variable of type testing.T to this function - gomock.NewController(). Since this is a kind of initialization for all the test cases, I want to do this in TestMain. But TestMain has access to only testing.M So how do I handle this case? Create a new testing.T structure in TestMain? Will it work?
Using testing.T in TestMain
3.5k views Asked by aniztar At
1
It sounds like you are looking for a
BeforeEachpattern. You don't have access to atesting.Tobject inTestMainbecause this is something more of a place to do initialization before and after the test suite runs.There are a few frameworks out there that can give you a
BeforeEachcheap:to name a few.
You could also hand roll your own: