Description
Gary Russell opened SPR-11576 and commented
Currently, when using @ContextConfiguration
and SpringJunit4ClassRunner
, the context is only close()
d (AFTER CLASS) if the class is annotated with @DirtiesContext
.
I don't know if this is a change in behavior or has always been this way, but it seems non-intuitive to me, given that the context is no longer available for use.
With "active" contexts (such as Spring Integration) this can cause issues when many tests are run, for example in a gradle build. Aside from the memory/cpu, it can cause unfortunate side effects (such as MBean name collisions, test cross-talk when using the same JMS queue name, etc).
We have started to mark our tests with class-level DirtiesContext
but I wonder if this behavior is intentional.
If this would be considered too big a change, perhaps we could consider a system property, e.g. spring.always.close.test.context.after.class
?
Affects: 3.0 GA
Issue Links:
- Use soft or weak references for context caching in the TestContext framework [SPR-7687] #12343 Use soft or weak references for context caching in the TestContext framework
- Limit size of context cache in the TestContext framework [SPR-8055] #12710 Limit size of context cache in the TestContext framework