Skip to content
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 @EnabledIf and @DisabledIf without loading ApplicationContext [SPR-14649] #19215

Closed
2 tasks done
spring-projects-issues opened this issue Aug 31, 2016 · 1 comment
Closed
2 tasks done

Comments

@spring-projects-issues
Copy link
Task lists! Give feedback
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 31, 2016

Sam Brannen opened SPR-14649 and commented

Status Quo

The recently added support for @EnabledIf and @DisabledIf allows for conditional test execution in JUnit Jupiter via SpEL expressions and property look-ups in the Spring Environment.

This functionality is extremely powerful; however, there is also a very large drawback with the current implementation. Namely, the test's ApplicationContext is always eagerly loaded, even if the ApplicationContext will never be used by a test.

Deliverables

  1. Introduce a boolean flag in @EnabledIf and @DisabledIf to control whether the test's ApplicationContext should be eagerly loaded.
    • set the default for the flag to false so that users have to explicitly think about the consequences.
  2. Introduce code for evaluating the following when the test's ApplicationContext is not available:
    • property placeholders for system properties and environment variables
    • SpEL expressions that do not access beans from the ApplicationContext

Affects: 5.0 M2

Issue Links:

  • #19181 Introduce support for disabling JUnit Jupiter tests with SpEL expressions ("depends on")
  • #19210 Introduce support for enabling JUnit Jupiter tests with SpEL expressions ("depends on")

Referenced from: commits 5c9350b

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 27, 2016

Sam Brannen commented

Resolved as described in GitHub commit 5c9350b:

Support @EnabledIf & @DisabledIf w/o loading ApplicationContext

Prior to this commit, when using @EnabledIf or @DisabledIf in Spring's
JUnit Jupiter support, the test's ApplicationContext was always eagerly
loaded, even if the ApplicationContext would never be used (i.e., the
test was disabled). This behavior can lead to undesirable side effects

  • for example, attempting to load an application context that requires
    services only available on the CI server when the test is not actually
    running on the CI server.

This commit addresses this issue by introducing new boolean
loadContext flags in @EnabledIf and @DisabledIf. By default these
flags are set to false which means that the user's test application
context will not be loaded to evaluate the expression. On the contrary,
a dummy application context will be loaded instead, and expressions
will be evaluated against that dummy context. Consequently, if the user
wishes to interact with properties from the Spring Environment or with
beans from the test application context, the loadContext must be
explicitly set to true.

In addition, expressions which evaluate to a String must now evaluate
to exactly "true" or "false" (ignoring case and surrounding whitespace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants