Skip to content

Allow overriding @ActiveProfiles in test classes with system property [SPR-8982] #13622

Closed as not planned
@spring-projects-issues

Description

@spring-projects-issues

Alex opened SPR-8982 and commented

Status Quo

Support for setting the active bean definition profiles in an integration test within the Spring TestContext Framework (TCF) is currently limited to one of the following techniques:

  1. Providing a hard-coded list of profiles declared via the value or profiles attribute of @ActiveProfiles - since Spring Framework 3.1
  2. Specifying a custom ActiveProfilesResolver (which programmatically determines the active profiles) declared via the resolver attribute of @ActiveProfiles - since Spring Framework 4.0

In stand-alone or production code, Spring honors the spring.profiles.active system property for determining the set of active profiles to use when loading an ApplicationContext; however, the TCF ignores this system property, relying solely on configuration via @ActiveProfiles.


Proposals

  1. Provide the ability to override @ActiveProfiles specified in an integration test via the spring.profiles.active system property or some other system property specific to the TCF.
  2. Set the spring.profiles.active system property to the value specified via @ActiveProfiles
    • See comments in this issue for background.
    • This point likely warrants its own JIRA issue for proper consideration.

Implementation Notes

  • Consider introducing a new boolean flag in @ActiveProfiles that allows profiles declared via the annotation to be overridden by those defined via the spring.profiles.active system property (if it is present).

Further Resources

Related discussions at Stack Overflow:


Affects: 3.1 GA

Issue Links:

19 votes, 24 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    has: votes-jiraIssues migrated from JIRA with more than 10 votes at the time of importin: 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