Skip to content

Introduce BEFORE_METHOD and BEFORE_CLASS modes for @DirtiesContext [SPR-12429] #17035

Closed

Description

@spring-projects-issues

Torsten Krah opened SPR-12429 and commented

Status Quo

@DirtiesContext currently only supports closing a test ApplicationContext after an entire test class or after a test method.

Proposal

It would be useful to have before class and before method modes, too.

Currently this is achievable with a custom TestExecutionListener which marks the context as dirty at the requested phase (before class or before method), but this could be easily achieved via new modes within the @DirtiesContext annotation.


Affects: 3.0 GA

Reference URL: http://stackoverflow.com/questions/26931236/is-it-possble-to-reset-spring-tests-context-cache-before-a-test-suite-runs-not

Issue Links:

Activity

  1. spring-projects-issues commented on Mar 22, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    Completed as described in GitHub commit e086a63:

    Introduce BEFORE METHOD/CLASS modes in @DirtiesContext

    Prior to this commit, @DirtiesContext could only be used to close a
    test ApplicationContext after an entire test class or after a test
    method; however, there are some use cases for which it would be
    beneficial to close a test ApplicationContext before a given test class
    or test method -- for example, if some rogue (i.e., yet to be
    determined) test within a large test suite has corrupted the original
    configuration for the ApplicationContext.

    This commit provides a solution to such testing challenges by
    introducing the following modes for @DirtiesContext.

    • MethodMode.BEFORE_METHOD: configured via the new methodMode attribute

    • ClassMode.BEFORE_CLASS and ClassMode.BEFORE_EACH_TEST_METHOD: both
      configured via the existing classMode attribute

  2. spring-projects-issues commented on Jul 1, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Sam Brannen commented

    FYI: a bug introduced in conjunction with this issue has been fixed in #17772.

  3. added
    in: test
    type: enhancement
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: testtype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions