Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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
✗ Incorrect
The @EnabledOnOs annotation requires the OS constant to specify which OS the test should run on. For Windows, use OS.WINDOWS.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Listing OS constants without braces
Using only one OS constant when multiple are needed
✗ Incorrect
To enable the test on multiple OS, list them inside the annotation separated by commas within the braces.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect casing like OS.mac or OS.Mac
Swapping the order like Mac.OS
✗ Incorrect
The OS constants are case-sensitive and must be exactly OS.MAC to work correctly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces
Forgetting the comma between OS constants
✗ Incorrect
To enable on multiple OS, list them inside the annotation separated by commas within braces. Here, Linux and Windows are OS.LINUX and OS.WINDOWS.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of braces
Missing commas between OS constants
Incorrect casing of OS constants
✗ Incorrect
The annotation lists all OS constants inside braces separated by commas. For Windows, Mac, and Linux, use OS.WINDOWS, OS.MAC, and OS.LINUX.