Newly-Introduced JUnit 5 Annotations and Classes. @DisplayName annotation
Newly-Introduced JUnit 5 Annotations and Classes. @DisplayName annotation
Abstract: JUnit is a unit testing framework for the Java programming language. The JUnit 5 version has been redesigned to solve some particular problems of the previous versions. It comes with a lot of new annotations that make the life of the programmer easier and nicer. This article will put a few of them in practice.
14 лип 2020
2246
Інші статті
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
1. The @DisplayName annotation
The @DisplayName annotation can be used over classes and test methods. It helps to declare our own display name for the annotated test class or test method. Typically, it’s used for test reporting in IDEs and build tools. The string argument of the @DisplayName annotation may contain spaces, special characters, and even emojis.Listing 1 demonstrates the usage of the @DisplayName annotation through the class displayname.DisplayNameTest. The name to be displayed is usually a full phrase to provide significant information about the purpose of the test.
The result of the execution of these tests from the IntelliJ IDE looks like in figure 1:
Figure 1 Running the DisplayNameTest in IntelliJ.
The execution of the example from listing 1 does the following:
- It shows the display name applied to the entire class (1).
- Then, we see that we may apply a usual text display name (2).
- We may also include an emoji (3). The test without an associated display name shows the method name.
Interested in JUnit? Check out our trainings.
Catalin Tudose
Java and Web Technologies Expert