0
0
JUnittesting~10 mins

@EnabledOnOs for OS-specific tests 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 on Windows OS.

JUnit
@EnabledOnOs([1])
void testWindowsFeature() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AOS.WINDOWS
BOS.LINUX
COS.MAC
DOS.UNIX
Attempts:
3 left
💡 Hint
Common Mistakes
Using OS.LINUX or OS.MAC instead of OS.WINDOWS
Forgetting to use curly braces {} around the OS constant
2fill in blank
medium

Complete the code to enable the test on both Linux and Mac OS.

JUnit
@EnabledOnOs([1])
void testUnixFeatures() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AOS.LINUX
BOS.LINUX, OS.MAC
COS.MAC
DOS.WINDOWS
Attempts:
3 left
💡 Hint
Common Mistakes
Listing OS constants without braces
Using only one OS constant when multiple are needed
3fill in blank
hard

Fix the error in the annotation to correctly enable the test on Mac OS.

JUnit
@EnabledOnOs([1])
void testMacFeature() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AOS.MAC
BOS.mac
CMac.OS
DOS.Mac
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing like OS.mac or OS.Mac
Swapping the order like Mac.OS
4fill in blank
hard

Fill both blanks to enable the test on Linux and Windows OS.

JUnit
@EnabledOnOs([1], [2] })
void testCrossPlatform() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AOS.LINUX
BOS.WINDOWS
COS.MAC
DOS.UNIX
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces
Forgetting the comma between OS constants
5fill in blank
hard

Fill all three blanks to enable the test on Windows, Mac, and Linux OS.

JUnit
@EnabledOnOs([1], [2], [3] })
void testAllPlatforms() {
    // test code here
}
Drag options to blanks, or click blank then click option'
AOS.WINDOWS
BOS.MAC
COS.LINUX
DOS.UNIX
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces
Missing commas between OS constants
Incorrect casing of OS constants