@DisplayName Annotation on Test Methods

This lesson demonstrates how to provide custom display names to test methods.

We'll cover the following

@DisplayName on @Test Methods

JUnit 5 @DisplayName annotation is also used to provide a custom name for the @Test methods. Usually, by default, JUnit 5 reporting prints the test methods name in the IDE test report and also while executing test cases. We can use @DisplayName annotation to provide a custom name to Test methods, that makes it easier to read. Thus, it acts as a metadata for our test methods.

@DisplayName annotation can take up string having the following things:-

  1. It can take spaces between words.
  2. It can take special characters.
  3. It can take emojis as well.

Let’s look at a demo:-

Get hands-on with 1200+ tech skills courses.