-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Support for @DirtiesContext at the test class level [SPR-4702] #9379
Comments
Noel Flicken commented This issue differs from #6700 in expected implementation. SPR_2007 is difficult to implement due to JUnit architectural limitations. This issue suggests a feature to optionally allow a context to be automatically closed after all test methods in a given Test Class are run, i.e. when JUnit |
Juergen Hoeller commented OK, good point - although I'm not entirely clear how exactly such Juergen |
Noel Flicken commented Fair enough. Allowing |
Eric Jain commented This would also be beneficial for TestNG tests (e.g. using AbstractTestNGSpringContextTests) where one would like to make use of TestNG's support for explicit dependencies between test methods. Not being able to control context reloading at the class level makes this feature a lot less useful (and the functional tests a lot uglier). |
Olaf Otto commented I would also like a convenient way to enforce context destruction after test class execution. In my specific case, I have observed that the refresh() that takes place on test class execution creates a seemingly new context but does not dispose old singletons (those are destroyed after all test classes have finished or if an exception is thrown...) which causes a significant memory consumption... |
Joost den Boer commented Destroying the context would be very welcome. I have several testcases with multiple testmethods which, when using I tried to work around it by creating a |
Sam Brannen commented
This is made possible via new support for 'before class' and 'after class' callbacks in the TestExecutionListener interface. DirtiesContextTestExecutionListener now implements afterTestClass(TestContext) which provides the class-level support for |
Sam Brannen commented Note: due to the limitations of JUnit 3.8, |
Sam Brannen commented Noel, Eric, Olaf, Joost, et al, Please try out this new functionality in one of the upcoming nightly snapshots or in 3.0.0.RC1, and let me know if this meets your needs. Note that using Thanks for all of your input! Sam |
Noel Flicken opened SPR-4702 and commented
Expected behavior:
Context should be close()'d after end of test class execution
Observed behavior:
Context only closed when
@DirtiesContext
annotates methodMultiple test classes can re-use the same context, which allows for faster test execution, so automatically closing a context after test class execution is probably not the best mechanism.
However, there should be a way to annotate that a context should be close()'d after all tests in a test class are executed.
Suggested fix:
@DirtiesContext
to annotate classWilling to implementing, if given approval of design.
Issue Links:
@ContextConfiguration
to implement integration tests ("is duplicated by")@ContextConfiguration
to implement integration testsReferenced from: commits 2dee54b, e77e070, 7782184, 0483cb5, 8dec6af, 1f087b4, 51b8b99, f26e2e3
4 votes, 6 watchers
The text was updated successfully, but these errors were encountered: