'Y'

Newly-Introduced JUnit 5 Annotations and Classes. The @Disabled annotation

The second part of our article on Newly-Introduced JUnit 5 Annotations and Classes. This time we look at @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.

usage of the @Disabled annotation on a test class.JPG


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.

usage of the @Disabled annotation on methods.JPG


You see that:
  1. The code provides two tests, both of them disabled.
  2. One of the tests is disabled without a given reason (1).
  3. 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.


Catalin Tudose
Java and Web Technologies Expert

Share the knowledge

Luxoft Warsaw - Warsaw Spire, plac Europejski 1, 00-844 Warszawa
Dimitrie Pompeiu nr 5-7 , building C, Et. 5, sect 2, Bucharest, 014459

Contact phone:

021 371 4858
Luxoft Poland Wroclaw - Silver Tower pl. Konstytucji 3-go Maja 3 50-048 Wroclaw
Aleja Generała Tadeusza Bora-Komorowskiego 25, Quattro Business Park Five, 31-476 Kraków, Poland

Contact phone:

+48 122110650
Success
Thank you.
Your request has been received.