@DisplayName Annotation in JUnit 5

The @DisplayName annotation is used to provide a custom name for your JUnit 5 test method. Let’s have a look how it is used in Java code.

Below, is a very simple code example of a JUnit 5 test method.  Notice how the @DisplayName annotation is used to provide a custom name for the text method.

@DisplayName("Test 4/2 = 2")
@Test
void testIntegerDivision_WhenFourIsDividedByTwo_ShouldReturnTwo() {
   // Arrange 

  // Act

  // Assert 
}

If @DisplayName annotation is not used then the name of the test method will be used in the test report instead.

Video Tutorial

This was a very short tutorial. If you are interested in learning more about JUnit, then have a look at other tutorials that teach how to test Java applications with JUnit 5 and Mockito.