1. The @DisplayName annotation
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.
Java and Web Technologies Expert