-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suite: Subtests should also trigger SetupTest
and TearDownTest
#1031
Comments
I'm not sure that makes sense. Probably you have a specific case and think you need a common solution. Probably you need to implement your sub-tests as separate tests. Or need a helper method in your suite to call it to setup subtests (if you use a table-driven test it will be clear and simple). If you can provide more details (or peace of code) I can suggest to you more detailed. I recommend investigating the flow of test execution. Look at this example — https://play.golang.org/p/ePSLrrfuV5m. SetupTest already executed before sub-test with other parent test code. So, proposed changes are the way to a sequence of SetupTest execution. I think you want to execute it once for every sub-test. SetupSubtest sounds better, but it is not clear what to do with a sub-sub-test. |
Because subtests in suite.Run() doesn't trigger SetupTest() and TearDownTest(), so we have to use a new user instead. Or we will get 'duplicate email' error. See this issue for more information: stretchr/testify#1031
I would also find |
Honestly I'm just shocked this still isn't a feature. It's pretty basic functionality considering they're clearly trying to imitate some of the concepts other test frameworks use (having hooks for pre- and post-tests) |
I needed a feature like
RSpec can be written as follows.
|
I haven't tried this, but can't you just call func (suite *MyTestSuite) TestSomeStuff() {
...
for _, testCase := range testCases {
suite.Run(testCase.name, func() {
suite.SetupTest()
...
suite.TearDownTest()
})
}
...
} |
I know this is probably a breaking change but I have some tests written using table driven design. I'd like for the tests ran with
suite.Run(name string, func(){})
to also triggerSetupTest
andTearDownTest
for every instance of the subtest.Is this currently possible?
If not then we can add a new func
SetupSubtest
andTearDownSubtest
and run those for every subtest.The text was updated successfully, but these errors were encountered: