Issue
I want to run some test classes and disable running some other test classes based on VM options. What are the possible ways to achieve this?
VM option will be like : -DENABLE_FEATURE1_TEST=false -DENABLE_FEATURE2_TEST=true
.
I have tried using Junit 5 property
@EnabledIfEnvironmentVariable(named = "ENABLE_FEATURE1_TEST", matches = "true")
on the test class, but using this still runs the tests in the class.
Similarly, i have also tried using @Conditional
annotation, with no success.
Solution
-DENABLE_FEATURE1_TEST=false
sets a JVM system property named ENABLE_FEATURE1_TEST
, not an operating system environment variable.
So, you would need to use:
@EnabledIfSystemProperty(named = "ENABLE_FEATURE1_TEST", matches = "true")
Answered By - Sam Brannen