Newly-Introduced JUnit 5 Annotations and Classes. The @Disabled annotation
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.
21 Jul 2020
1563
Other articles
How to incrementally migrate the data from RDBMS to Hadoop using Sqoop Incremental Last Modified technique?
How to implement Slowly Changing Dimensions(SCD) Type 2 in Spark?
How to incrementally migrate the data from RDBMS to Hadoop using Sqoop Incremental Append technique?
Why MongoDB don't fetch all the matching documents for the query fired
How to solve the issue of full disk utilization in HDFS Namenode
Can We Use HDFS as Back-up Storage?
How to do Indexing in MongoDB with Elastic Search? Part 1
How to do Indexing in MongoDB with Elastic Search? Part 2
How to store data on browser using NoSQL IndexedDB?
How to Apply MBTI in HR: Motivation for every day. Groups of People & their Motivations
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.
Interested in JUnit? Check out our trainings.
Catalin Tudose
Java and Web Technologies Expert