Annotations
Explore how to apply key JUnit 5 annotations such as @Test to mark test methods and @DisplayName to customize method names for readability in test reports. This lesson helps you write clear and effective basic tests using the most common JUnit 5 annotations.
We'll cover the following...
The @Test annotation
JUnit 5 uses different annotations to annotate test methods. The org.junit.jupiter.api.Test annotates a method as a test method executed by JUnit. The @Test annotation has no attributes.
The @DisplayName annotation
The org.junit.jupiter.api.DisplayName annotation adds custom display names to test classes and test methods. The @DisplayName annotation resolves the longtime debate about how to name test methods. Some developers want to use the standard testAddTwoNumbers, while others prefer the test_add_two_numbers. We’re now free to name test methods and use @DisplayName to add the names displayed in test runners and reports.