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