How to use @EnabledIfSystemProperty in an "or" fashion? #5052
-
I have to allow a set of integration tests to run or not run in certain "environments", like "dev", "test", "stage", and "prod". On the mvn command line I set the system property containing the current environment. I've verified that this annotation:
works if I wire it into the "systemPropertyVariables" block in failsafe. When that property is set with that value, then those tests are enabled and run. I've also implemented "wrapper" annotations like "EnabledOnDevEnv", "EnabledOnTestEnv", et cetera. These work fine in isolation. However, what I really need to be able to do is specify that certain tests can run in the dev environment OR the test environment. I want to be able to put the following on a test class:
To ensure that this test class will run in either of those environments. This is not working. These conditions are apparently ANDed together, so although the "dev" test is true, the "test" test is false, so the test is not enabled. Am I going to have to implement a "EnabledOnEnv" annotation with a "matches" parameter value like "dev | test"? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes, you'll need to move the boolean logic to a regular expression. Perhaps something like this: @Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@EnabledIfSystemProperty(
named = "INTEGRATION_TEST_ENV", matches = "(dev|test)",
disabledReason = "Not currently executing in dev or test environment")
public @interface EnabledOnDevOrTestEnvironment {
} Or implement your own custom |
Beta Was this translation helpful? Give feedback.
Yes, you'll need to move the boolean logic to a regular expression.
Perhaps something like this:
Or implement your own custom
ExecutionCondition
.