0
0
JUnittesting~20 mins

@Disabled for skipping tests in JUnit - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
JUnit @Disabled Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of @Disabled Annotation in JUnit
What is the primary purpose of the @Disabled annotation in JUnit 5?
ATo run a test multiple times automatically
BTo mark a test as expected to fail
CTo enable parallel execution of tests
DTo temporarily skip the execution of a test method or class
Attempts:
2 left
💡 Hint
Think about why you might want to prevent a test from running temporarily.
Predict Output
intermediate
2:00remaining
Effect of @Disabled on Test Execution Count
Given the following JUnit 5 test class, how many tests will be executed when running this class?
JUnit
import org.junit.jupiter.api.*;

public class SampleTest {

    @Test
    void testOne() {
        System.out.println("Test One");
    }

    @Disabled
    @Test
    void testTwo() {
        System.out.println("Test Two");
    }

    @Test
    void testThree() {
        System.out.println("Test Three");
    }
}
A2
B3
C1
D0
Attempts:
2 left
💡 Hint
Count only tests that are not disabled.
assertion
advanced
1:30remaining
Assertion Behavior in Disabled Tests
Consider a test method annotated with @Disabled that contains failing assertions. What will be the test result when running this test?
AThe test will be skipped and no assertion failures reported
BThe test will fail due to assertion errors
CThe test will pass regardless of assertions
DThe test will run but report warnings instead of failures
Attempts:
2 left
💡 Hint
Think about whether the test code runs at all when disabled.
🔧 Debug
advanced
2:00remaining
Why is a Disabled Test Still Running?
A developer added @Disabled to a test method, but the test still runs during the test suite execution. Which of the following is the most likely cause?
AThe test runner does not support <code>@Disabled</code>
BThe test method is missing the <code>@Test</code> annotation
CThe <code>@Disabled</code> annotation was imported from the wrong package
DThe test method is private instead of public
Attempts:
2 left
💡 Hint
Check the import statements for annotations.
framework
expert
2:30remaining
Combining @Disabled with Conditional Test Execution
In JUnit 5, if a test method is annotated with both @Disabled and a conditional annotation like @EnabledOnOs(OS.WINDOWS), what will happen when running the tests on a Windows machine?
AJUnit will throw an error due to conflicting annotations
BThe test will be skipped because @Disabled takes precedence over conditional annotations
CThe test will run because the condition is met, ignoring @Disabled
DThe test will run only if both annotations allow it, so it runs on Windows
Attempts:
2 left
💡 Hint
Consider the priority of @Disabled in test execution.