Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to enable the test only if the system property 'env' equals 'test'.
JUnit
@EnabledIfSystemProperty(named = "env", matches = "[1]") void testEnvironment() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property value in 'matches' so the test never runs.
Confusing 'named' with the property value.
✗ Incorrect
The test runs only when the system property 'env' matches 'test'.
2fill in blank
mediumComplete the code to enable the test only if the system property 'os.name' contains 'Linux'.
JUnit
@EnabledIfSystemProperty(named = "os.name", matches = ".*[1].*") void testOnLinux() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using regex wildcards '.*' causing the test not to run.
Using incorrect OS name spelling.
✗ Incorrect
The regex '.*Linux.*' matches any string containing 'Linux', enabling the test on Linux OS.
3fill in blank
hardFix the error in the annotation to enable the test only if the system property 'user.language' equals 'en'.
JUnit
@EnabledIfSystemProperty(named = "user.language", matches = "[1]") void testEnglishLanguage() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or mixed case causing the test not to run.
Confusing language codes with country codes.
✗ Incorrect
System properties are case-sensitive; 'en' is the correct lowercase code for English language.
4fill in blank
hardFill both blanks to enable the test only if the system property 'java.version' starts with '17'.
JUnit
@EnabledIfSystemProperty(named = "[1]", matches = "[2].*") void testJava17() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong system property name.
Incorrect regex pattern causing test not to run.
✗ Incorrect
The test runs only if 'java.version' starts with '17', matching the regex '17.*'.
5fill in blank
hardFill all three blanks to enable the test only if the system property 'user.timezone' equals 'UTC' and the property 'env' equals 'prod'.
JUnit
@EnabledIfSystemProperty(named = "[1]", matches = "[2]") @EnabledIfSystemProperty(named = "[3]", matches = "prod") void testProdUTC() { // test code here }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing property names or values between annotations.
Using incorrect property names causing test not to run.
✗ Incorrect
The first annotation checks 'user.timezone' equals 'UTC', the second checks 'env' equals 'prod'. Both must be true to enable the test.