Skip to content

Introduce system property to disable context caching in the TestContext framework [SPR-11576] #16200

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions