0
0
JUnittesting~10 mins

@EnabledIfSystemProperty in JUnit - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Aprod
Btest
Cdev
Dstage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property value in 'matches' so the test never runs.
Confusing 'named' with the property value.
2fill in blank
medium

Complete 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'
ALinux
BMac
CWindows
DUnix
Attempts:
3 left
💡 Hint
Common Mistakes
Not using regex wildcards '.*' causing the test not to run.
Using incorrect OS name spelling.
3fill in blank
hard

Fix 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'
AEN
BeN
CEn
Den
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or mixed case causing the test not to run.
Confusing language codes with country codes.
4fill in blank
hard

Fill 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'
Ajava.version
Bjava.home
C17
D18
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong system property name.
Incorrect regex pattern causing test not to run.
5fill in blank
hard

Fill 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'
Auser.timezone
BUTC
Cenv
Dtimezone
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing property names or values between annotations.
Using incorrect property names causing test not to run.