0
0
JUnittesting~10 mins

@EnabledIfEnvironmentVariable 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 environment variable 'ENV' equals 'test'.

JUnit
@EnabledIfEnvironmentVariable(named = "ENV", matches = "[1]")
void testFeature() {
    // test code here
}
Drag options to blanks, or click blank then click option'
Aprod
Bstaging
Cdev
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong environment variable value in 'matches'.
Forgetting to use quotes around the match string.
2fill in blank
medium

Complete the code to enable the test only if the environment variable 'MODE' matches 'debug'.

JUnit
@EnabledIfEnvironmentVariable(named = "MODE", matches = "[1]")
void debugTest() {
    // debug test code
}
Drag options to blanks, or click blank then click option'
Adebug
Bproduction
Crelease
Dtest
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Debug' instead of 'debug' (case mismatch).
Confusing 'MODE' with other environment variables.
3fill in blank
hard

Fix the error in the annotation to enable the test only if the environment variable 'APP_ENV' equals 'production'.

JUnit
@EnabledIfEnvironmentVariable(named = "APP_ENV", matches = "[1]")
void productionTest() {
    // production test code
}
Drag options to blanks, or click blank then click option'
AProduction
Bprod
Cproduction
DPRODUCTION
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase or capitalized strings that do not match the environment variable.
Using shorthand like 'prod' instead of full 'production'.
4fill in blank
hard

Fill both blanks to enable the test only if the environment variable 'TEST_ENV' matches 'qa' and the method name is 'qaTest'.

JUnit
@EnabledIfEnvironmentVariable(named = "[1]", matches = "[2]")
void qaTest() {
    // QA environment test
}
Drag options to blanks, or click blank then click option'
ATEST_ENV
Bqa
Cprod
Ddev
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the environment variable name and value.
Using incorrect environment variable names.
5fill in blank
hard

Fill all three blanks to enable the test only if the environment variable 'BUILD_TYPE' matches 'nightly' and the method name is 'nightlyBuildTest'.

JUnit
@EnabledIfEnvironmentVariable(named = "[1]", matches = "[2]")
void [3]() {
    // Nightly build test
}
Drag options to blanks, or click blank then click option'
ABUILD_TYPE
Bnightly
CnightlyBuildTest
Drelease
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong environment variable names or values.
Mismatch between method name and the test purpose.