This version is still in development and is not considered stable yet.
For the latest stable version, please use JUnit 6.0.1!

Disabling Tests

Entire test classes or individual test methods may be disabled via the @Disabled annotation, via one of the annotations discussed in Conditional Test Execution, or via a custom ExecutionCondition.

When @Disabled is applied at the class level, all test methods within that class are automatically disabled as well.

If a test method is disabled via @Disabled, that prevents execution of the test method and method-level lifecycle callbacks such as @BeforeEach methods, @AfterEach methods, and corresponding extension APIs. However, that does not prevent the test class from being instantiated, and it does not prevent the execution of class-level lifecycle callbacks such as @BeforeAll methods, @AfterAll methods, and corresponding extension APIs.

Here’s a @Disabled test class.

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

@Disabled("Disabled until bug #99 has been fixed")
class DisabledClassDemo {

	@Test
	void testWillBeSkipped() {
	}

}

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

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

class DisabledTestsDemo {

	@Disabled("Disabled until bug #42 has been resolved")
	@Test
	void testWillBeSkipped() {
	}

	@Test
	void testWillBeExecuted() {
	}

}

@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.

@Disabled is not @Inherited. Consequently, if you wish to disable a class whose superclass is @Disabled, you must redeclare @Disabled on the subclass.