O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Display names

JUnit 4 identified tests basically with the name of the method annotated with @Test. This imposes a limitation on name tests, since these names are constrained by the way of declaring methods in Java.

To overcome this problem, Jupiter provides the ability of declaring a custom display name (different to the test name) for tests. This is done with the annotation @DisplayName. This annotation declares a custom display name for a test class or a test method. This name will be displayed by test runners and reporting tools, and it can contain spaces, special characters, and even emojis.

Take a look at the following example. We are annotating the test class, and also the three test methods declared inside the class with a custom test ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required