0
0
JUnittesting~10 mins

@Disabled for skipping tests in JUnit - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test demonstrates how to use the @Disabled annotation in JUnit to skip a test method. The test verifies that a simple addition operation works correctly, but the test is skipped during execution.

Test Code - JUnit
JUnit
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class CalculatorTest {

    @Test
    @Disabled("Skipping this test temporarily")
    void testAddition() {
        int result = 2 + 3;
        assertEquals(5, result, "2 + 3 should equal 5");
    }
}
Execution Trace - 3 Steps
StepActionSystem StateAssertionResult
1Test runner discovers testAddition method annotated with @Test and @DisabledTest suite loaded with one test method marked as disabled-PASS
2Test runner skips execution of testAddition due to @Disabled annotationNo browser or UI involved; test framework skips test executionNo assertions executed because test is skippedPASS
3Test report marks testAddition as skippedTest report shows one skipped testSkipped test is correctly reportedPASS
Failure Scenario
Failing Condition: Test is not skipped because @Disabled annotation is missing or misspelled
Execution Trace Quiz - 3 Questions
Test your understanding
What does the @Disabled annotation do in this JUnit test?
ASkips the test method during execution
BRuns the test method twice
CMarks the test as failed
DAutomatically fixes test errors
Key Result
Using @Disabled allows you to temporarily skip tests without deleting code, helping manage test suites during development or debugging.