0
0
JUnittesting~5 mins

@EnabledIfSystemProperty in JUnit - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @EnabledIfSystemProperty annotation do in JUnit?
It enables a test or test class only if a specified system property matches a given value. If the condition is not met, the test is skipped.
Click to reveal answer
beginner
How do you specify the system property name and value in @EnabledIfSystemProperty?
You use the attributes 'named' for the system property name and 'matches' for the expected value pattern. For example: @EnabledIfSystemProperty(named = "os.name", matches = "Windows.*")
Click to reveal answer
intermediate
Can @EnabledIfSystemProperty use regular expressions for matching the property value?
Yes, the 'matches' attribute accepts a regular expression to match the system property value.
Click to reveal answer
beginner
What happens if the system property specified in @EnabledIfSystemProperty is not set?
The test is disabled (skipped) because the condition to enable it is not met.
Click to reveal answer
beginner
Write a simple example of a test method enabled only on Linux OS using @EnabledIfSystemProperty.
@EnabledIfSystemProperty(named = "os.name", matches = "Linux.*") void testOnlyOnLinux() { // test code here }
Click to reveal answer
What does @EnabledIfSystemProperty do in JUnit?
ARuns a test only if an environment variable is set
BDisables a test permanently
CRuns a test only if a system property matches a value
DRuns all tests regardless of conditions
Which attribute specifies the system property name in @EnabledIfSystemProperty?
Anamed
BpropertyName
Cvalue
Dkey
If the system property does not exist, what happens to the test with @EnabledIfSystemProperty?
ATest runs normally
BTest is skipped
CTest fails
DTest runs twice
Can the 'matches' attribute in @EnabledIfSystemProperty use regular expressions?
AYes, it supports regex
BIt accepts only numeric values
COnly wildcards (*) are allowed
DNo, only exact matches
Which of these is a valid use of @EnabledIfSystemProperty?
A@EnabledIfSystemProperty(enabled = true)
B@EnabledIfSystemProperty(env = "PATH")
C@EnabledIfSystemProperty(property = "user.home")
D@EnabledIfSystemProperty(named = "java.version", matches = "17.*")
Explain how @EnabledIfSystemProperty controls test execution in JUnit.
Think about how system properties can control when tests run.
You got /4 concepts.
    Describe a scenario where using @EnabledIfSystemProperty would be helpful.
    Consider different machines or environments where tests run.
    You got /4 concepts.