@Disabled is the JUnit 5 (Jupiter) annotation that tells the engine to skip a test method or an entire test class. The skipped tests are reported as skipped instead of passed or failed, so they stay visible in the results. It replaces @Ignore from JUnit 4.
Use it for tests that cannot run right now, always with a reason, and plan to remove it.
@Disabled lives in org.junit.jupiter.api and has one optional attribute, value, which holds the reason. The Jupiter engine checks it before running a test, marks the test as skipped, and shows the reason in the console, IDE and build reports.
When you run the class, the build tool reports one passed test and one skipped test. Skipped tests do not fail the build.
Put the annotation on the class to skip every test method and lifecycle callback inside it:
The class and all its tests appear as skipped. This is more honest than commenting the code out, because the number of skipped tests stays in your reports and reminds the team that work is pending.
| JUnit 4 | JUnit 5 | Note |
|---|---|---|
@Ignore | @Disabled | Same idea, different package |
@Ignore("reason") | @Disabled("reason") | The reason is optional in both |
| Assumptions in code | Assumptions and conditional annotations | See the next section |
If you still have JUnit 4 tests running through the Vintage engine, @Ignore keeps working there. For new code, use @Disabled and the Jupiter API.
@Disabled is unconditional. When a test should run only in some environments, JUnit 5 has condition annotations that are better suited, because they skip the test automatically when the condition is not met:
The other condition annotations include @EnabledIf and @DisabledIf (which call a method), @EnabledIfSystemProperty and @DisabledIfEnvironmentVariable. You can also call Assumptions.assumeTrue(...) inside a test to abort it at runtime.
@Disabled works on @ParameterizedTest, @RepeatedTest and @Nested classes. Applied to the method, it skips all invocations:
To skip only some data, filter the arguments or use an Assumptions call inside the method instead.
Sometimes you want to skip tests without editing code:
mvn test -Dtest='!SlowTest' excludes a class, and -DskipTests skips all tests.gradle test --tests selects tests, and exclude rules in the test task filter classes.@Tag("slow") and exclude the tag in the build configuration.Tags are usually the right tool for categories such as slow or integration tests. @Disabled is for tests that are broken or blocked.
@RepeatedTest or logs to find the cause.@Disabled from org.junit.jupiter.api. It can be placed on methods and classes.
No. It is reported as skipped, so it appears in the totals but does not count as a pass or a failure.
Yes. Use @DisabledOnOs(OS.WINDOWS) or a similar condition annotation instead of @Disabled.
Yes. Spring Boot tests use JUnit Jupiter, so @Disabled skips them, and a skipped class does not start the application context.
@Disabled skips a JUnit 5 test method or class and reports it as skipped with an optional reason. Use it sparingly for blocked tests, prefer conditional annotations for environment-specific tests, and tags for test categories. A short reason and a plan to re-enable the test keep the suite trustworthy.