Open sirzooro opened 1 month ago
hi @sirzooro
I'm no expert for the suite
interfaces, but can you use SetupSuite
and TearDownSuite
?
I looked for more doc of the ordering but I still can't find the complete docs. might do some testing when I have the time
SetupSuite
and TearDownSuite
are called before 1st test and after last one, respectively. They are useful to perform some costly global initialization and cleanup for whole test suite, e.g. setup test DB before all tests and shut it down after all tests are completed. So no, they do not satisfy my needs.
And yes, docs does not specify ordering, one has to check this in the code. It would be good to add this to the docs.
I always check source code of suite.Run
when I need to check it: https://github.com/stretchr/testify/blob/master/suite/suite.go#L121
I see, thank you for explaining.
I was thinking of just adding your operations that you want to be before SetupTest
just on the start of the SetupTest
itself, so no need to add another wrapper for this since both SetupTest
and your suggested feature is executed in order on each tests.
does that make sense to you?
Description
Methods of existing
BeforeTest
andAfterTest
interfaces are called afterSetupTest
and beforeTearDownTest
ones. I need ones which are called before and after them, i.e. "wrap" whole test with its Setup and TestDown parts. Please add new interfacesBeforeSetupTest
andAfterTearDownTest
for this.Use case
I have custom Suite type which wraps
suite.Suite
. I want to do extra things before and after each test, like printing custom start/end messages and checking for goroutine leaks. For subtests I was able to provide my ownRun
method which internally calls one fromsuite.Suite
. For tests there is no easy way to do this.