Skip to content
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

Feature request: add BeforeSetupTest and AfterTearDownTest #1604

Open
sirzooro opened this issue May 30, 2024 · 3 comments
Open

Feature request: add BeforeSetupTest and AfterTearDownTest #1604

sirzooro opened this issue May 30, 2024 · 3 comments

Comments

@sirzooro
Copy link

Description

Methods of existing BeforeTest and AfterTest interfaces are called after SetupTest and before TearDownTest 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 interfaces BeforeSetupTest and AfterTearDownTest 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 own Run method which internally calls one from suite.Suite. For tests there is no easy way to do this.

@hendrywiranto
Copy link
Contributor

hendrywiranto commented Jun 11, 2024

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

@sirzooro
Copy link
Author

sirzooro commented Jun 11, 2024

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

@hendrywiranto
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants