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?
✗ Incorrect
The annotation enables tests only when a system property matches the specified value.
Which attribute specifies the system property name in @EnabledIfSystemProperty?
✗ Incorrect
The 'named' attribute is used to specify the system property name.
If the system property does not exist, what happens to the test with @EnabledIfSystemProperty?
✗ Incorrect
The test is skipped because the enabling condition is not met.
Can the 'matches' attribute in @EnabledIfSystemProperty use regular expressions?
✗ Incorrect
The 'matches' attribute supports regular expressions for flexible matching.
Which of these is a valid use of @EnabledIfSystemProperty?
✗ Incorrect
Only option A correctly uses 'named' and 'matches' attributes.
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.