2.6. Disabling Tests

Entire test classes or individual test methods may be disabled via the [@Disabled](https://junit.org/junit5/docs/current/api/org.junit.jupiter.api/org/junit/jupiter/api/Disabled.html) annotation, via one of the annotations discussed in Conditional Test Execution, or via a custom ExecutionCondition.

Here’s a @Disabled test class.

  1. import org.junit.jupiter.api.Disabled;
  2. import org.junit.jupiter.api.Test;
  3. @Disabled("Disabled until bug #99 has been fixed")
  4. class DisabledClassDemo {
  5. @Test
  6. void testWillBeSkipped() {
  7. }
  8. }

And here’s a test class that contains a @Disabled test method.

  1. import org.junit.jupiter.api.Disabled;
  2. import org.junit.jupiter.api.Test;
  3. class DisabledTestsDemo {
  4. @Disabled("Disabled until bug #42 has been resolved")
  5. @Test
  6. void testWillBeSkipped() {
  7. }
  8. @Test
  9. void testWillBeExecuted() {
  10. }
  11. }
@Disabled may be declared without providing a reason; however, the JUnit team recommends that developers provide a short explanation for why a test class or test method has been disabled. Consequently, the above examples both show the use of a reason — for example, @Disabled(“Disabled until bug #42 has been resolved”). Some development teams even require the presence of issue tracking numbers in the reason for automated traceability, etc.