In this article, we’ll have a look at the display names and technical names in JUnit 5, what are they and how to use them?

1. Technical Names in JUnit 5

In JUnit 5, technical names are often referred to the full qualified name of a test class or  the test method name itself.

Let’s say we have an test class with some test methods as the following:

Here are some technical names of the test class and test methods printed out when we run JUnit tests in Eclipse:

Display names and technical names in JUnit 5 - JUnit 5 Technical Names Example

JUnit 5 Technical Names Example

We can see that the qualified full name of the test class and the test methods are printed out.

2. Display Names in JUnit 5

In JUnit 5, display names are custom names declared for test classes and test methods. These names,  annotated with @DisplayName annotation, can contains spaces, special characters, and even emojis, will be displayed by test runners and test reporting.

Let’s see an example test class as below:

We have defined the custom display names for the test class and two first test methods. Let’s see the output when we run the test in Eclipse:

Custom Display Names in JUnit 5

JUnit 5 Custom Display Names Example

All the custom displayed names are printed out in the test result.

3. Display Names vs. Technical Names

By default, display names will be used for test artifacts. However, when we execute tests with a build tool such as Gradle or Maven, the generated test report often needs to include the technical names of test. To enable technical names for reporting purposes, simply declare the @UseTechnicalNames annotation alongside @RunWith(JUnitPlatform.class).

4. Conclusion

The article has just explained about display names and technical names in JUnit 5. The display names, which were not supported in the previous versions of JUnit,  offers us a flexible ways to declare custom names for the test artifacts while the technical names are suitable for reporting purposes.

If you want to get to know more features of JUnit 5, you can refer to the following articles:

JUnit 5 Tutorial

JUnit 5 Annotations Example

JUnit 5 Basic Introduction – Getting Started With The Next Generation of JUnit

JUnit 5 with Gradle Example

JUnit 5 Maven Example

JUnit 5 vs JUnit 4

JUnit 5 Assertions Example

JUnit 5 Disable or Ignore A Test

JUnit 5 Exception Testing

JUnit 5 Dynamic Tests – Generate Tests at Run-time

JUnit 5 Nested Tests Examples

JUnit 5 Test Suite – Aggregating Tests In Suites

JUnit 5 Assumptions With Assume

JUnit 5 Parameter Resolution Example

0 0 vote
Article Rating