2. The @Disabled annotation
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
. 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.
Interested in JUnit? Check out our trainings.
Java and Web Technologies Expert