Newly-Introduced JUnit 5 Annotations and Classes. The @Disabled annotation
2. The @Disabled annotation
The @Disabled annotation can be used over classes and test methods. It’s used to signal that the annotated test class or test method is currently disabled and shouldn’t be executed. We should give reasons for disabling a test, allowing the rest of your team to know exactly why this has been done. If it’s applied on a class, it disables all the methods of the test. The disabled tests are also shown differently when each programmer is running them from the IDE, and the disabling reason is displayed into their console.
The usage of the annotation is demonstrated by the classes disabled.DisabledClassTest and disabled.DisabledMethodsTest. Listings 2 and 3 show the code for these classes.
The whole testing class is disabled, and a reason is provided (1). This is the recommended way to work, providing your colleagues (or maybe, at a later time, even you, the author of the class) immediate understanding about why the test isn’t enabled right now.
You see that:
- The code provides two tests, both of them disabled.
- One of the tests is disabled without a given reason (1).
- The other test is disabled with a reason that may be quickly understood (2) – the recommended way to work.