Close

JUnit 5 - Disabling Tests with @Disabled

[Last Updated: Dec 4, 2025]

JUnit Jupiter provides @Disabled to skip a test or an entire test class. We should use this annotation, when we know what tests should be enabled/disabled before compiling the code.
This is useful when a feature is incomplete or blocked by an external dependency.

Definition of Disabled

(Version: junit-5 6.0.1)
package org.junit.jupiter.api;
   ........
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@API(status = STABLE, since = "5.0")
public @interface Disabled {
    String value() default ""; 1
}
1 The reason this annotated test class or test method is disabled.

Overview

  • Apply @Disabled on a test method or on the test class.
  • Provide an optional reason to document why the test is disabled.
  • Disabled tests are reported as skipped in IDEs and build tools.
  • We should prefer conditional annotations (see next pages) when the condition is dynamic.

Example

Class-level @Disabled

package com.logicbig.example;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;

@Disabled("Whole class is disabled for demonstration")
class ClassDisabledExampleTest {

    @Test
    void willNotRun_one() {
        assertTrue(true);
    }

    @Test
    void willNotRun_two() {
        assertTrue(true);
    }
}
mvn test -Dtest=ClassDisabledExampleTest

Output

D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations>mvn test -Dtest=ClassDisabledExampleTest
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.logicbig.example:junit-5-disabled-annotations >----------
[INFO] Building junit-5-disabled-annotations 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\main\resources
[INFO]
[INFO] --- compiler:3.14.1:compile (default-compile) @ junit-5-disabled-annotations ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\test\resources
[INFO]
[INFO] --- compiler:3.14.1:testCompile (default-testCompile) @ junit-5-disabled-annotations ---
[INFO] Recompiling the module because of changed source code.
[INFO] Compiling 2 source files with javac [debug target 25] to target\test-classes
[INFO]
[INFO] --- surefire:3.5.0:test (default-test) @ junit-5-disabled-annotations ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] +--com.logicbig.example.ClassDisabledExampleTest - 0.011 ss
[INFO] | +-- [??] willNotRun_one (Whole class is disabled for demonstration) - 0 ss
[INFO] | '-- [??] willNotRun_two (Whole class is disabled for demonstration) - 0 ss
[INFO]
[INFO] Results:
[INFO]
[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.667 s
[INFO] Finished at: 2025-12-03T19:56:04+08:00
[INFO] ------------------------------------------------------------------------

Method-level @Disabled

package com.logicbig.example;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MethodDisabledExampleTest {

    @Test
    void active_test_runs_normally() {
        assertEquals(4, 2 + 2);
    }

    @Test
    @Disabled("Temporarily disabled due to bug #123")
    void disabled_test_will_be_skipped() {
        assertEquals(5, 2 + 3);
    }
}
mvn test -Dtest=MethodDisabledExampleTest

Output

D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations>mvn test -Dtest=MethodDisabledExampleTest
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.logicbig.example:junit-5-disabled-annotations >----------
[INFO] Building junit-5-disabled-annotations 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\main\resources
[INFO]
[INFO] --- compiler:3.14.1:compile (default-compile) @ junit-5-disabled-annotations ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\test\resources
[INFO]
[INFO] --- compiler:3.14.1:testCompile (default-testCompile) @ junit-5-disabled-annotations ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- surefire:3.5.0:test (default-test) @ junit-5-disabled-annotations ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] +--com.logicbig.example.MethodDisabledExampleTest - 0.087 ss
[INFO] | +-- [??] disabled_test_will_be_skipped (Temporarily disabled due to bug #123) - 0 ss
[INFO] | '-- [OK] active_test_runs_normally - 0.034 ss
[INFO]
[INFO] Results:
[INFO]
[WARNING] Tests run: 2, Failures: 0, Errors: 0, Skipped: 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.286 s
[INFO] Finished at: 2025-12-03T19:56:09+08:00
[INFO] ------------------------------------------------------------------------

Run all

mvn test

Output

D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.logicbig.example:junit-5-disabled-annotations >----------
[INFO] Building junit-5-disabled-annotations 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- resources:3.3.1:resources (default-resources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\main\resources
[INFO]
[INFO] --- compiler:3.14.1:compile (default-compile) @ junit-5-disabled-annotations ---
[INFO] No sources to compile
[INFO]
[INFO] --- resources:3.3.1:testResources (default-testResources) @ junit-5-disabled-annotations ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\example-projects\junit-5\junit-5-enabling-disabling-tests\junit-5-disabled-annotations\src\test\resources
[INFO]
[INFO] --- compiler:3.14.1:testCompile (default-testCompile) @ junit-5-disabled-annotations ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- surefire:3.5.0:test (default-test) @ junit-5-disabled-annotations ---
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] +--com.logicbig.example.ClassDisabledExampleTest - 0.013 ss
[INFO] | +-- [??] willNotRun_one (Whole class is disabled for demonstration) - 0 ss
[INFO] | '-- [??] willNotRun_two (Whole class is disabled for demonstration) - 0 ss
[INFO] +--com.logicbig.example.MethodDisabledExampleTest - 0.069 ss
[INFO] | +-- [??] disabled_test_will_be_skipped (Temporarily disabled due to bug #123) - 0 ss
[INFO] | '-- [OK] active_test_runs_normally - 0.032 ss
[INFO]
[INFO] Results:
[INFO]
[WARNING] Tests run: 4, Failures: 0, Errors: 0, Skipped: 3
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.073 s
[INFO] Finished at: 2025-12-03T19:56:16+08:00
[INFO] ------------------------------------------------------------------------

Running in IntelliJ

Example Project

Dependencies and Technologies Used:

  • junit-jupiter-engine 6.0.1 (Module "junit-jupiter-engine" of JUnit)
     Version Compatibility: 5.0.0 - 6.0.1Version List
    ×

    Version compatibilities of junit-jupiter-engine with this example:

    • 5.0.0
    • 5.0.1
    • 5.0.2
    • 5.0.3
    • 5.1.0
    • 5.1.1
    • 5.2.0
    • 5.3.0
    • 5.3.1
    • 5.3.2
    • 5.4.0
    • 5.4.1
    • 5.4.2
    • 5.5.0
    • 5.5.1
    • 5.5.2
    • 5.6.0
    • 5.6.1
    • 5.6.2
    • 5.6.3
    • 5.7.0
    • 5.7.1
    • 5.7.2
    • 5.8.0
    • 5.8.1
    • 5.8.2
    • 5.9.0
    • 5.9.1
    • 5.9.2
    • 5.9.3
    • 5.10.0
    • 5.10.1
    • 5.10.2
    • 5.10.3
    • 5.10.4
    • 5.10.5
    • 5.11.0
    • 5.11.1
    • 5.11.2
    • 5.11.3
    • 5.11.4
    • 5.12.0
    • 5.12.1
    • 5.12.2
    • 5.13.0
    • 5.13.1
    • 5.13.2
    • 5.13.3
    • 5.13.4
    • 5.14.0
    • 5.14.1
    • 6.0.0
    • 6.0.1

    Versions in green have been tested.

  • JDK 25
  • Maven 3.9.11

JUnit 5 - Disabled Annotations Select All Download
  • junit-5-disabled-annotations
    • src
      • test
        • java
          • com
            • logicbig
              • example
                • MethodDisabledExampleTest.java

    See Also