HOME BLOG

Archive for the ‘Java’ Category

How to disable a test class or method in Java

Posted on: April 26th, 2024 by Olu No Comments

Hi folks,

In this brief post, we will talk about how to disable a test class or method in a Java-based project. Why would you want to do this? It could be because the test isn’t yet fully implemented. Another situation is if you have Continuous Integration in place where tests are run automatically during a build, but a certain test class isn’t yet ready for automatic execution.

To disable a test class or method, you can use the Disabled annotation from JUnit. E.g.

import org.junit.jupiter.api.Disabled
...

@Disabled
class YourTestClass {
...
}

That’s it. Now such a test would be ignored. That’s all for now. Till next time, happy software development.

 

References

Disabled (JUnit 5.0.0-M2 API). https://junit.org/junit5/docs/5.0.0-M2/api/org/junit/jupiter/api/Disabled.html