...
Code Block |
---|
import org.junit.jupiter.api.*; @DisplayName("JUnit 5 Example") class JUnit5ExampleTest { @BeforeAll static void beforeAll() { System.out.println("Before all test methods"); } @BeforeEach void beforeEach() { System.out.println("Before each test method"); } @AfterEach void afterEach() { System.out.println("After each test method"); } @AfterAll static void afterAll() { System.out.println("After all test methods"); } } |
@DisplayName and @Disabled
Now let's move to new test-optional methods:
...
@DisplayName
(
"Single test successful"
)
@Test
void
testSingleSuccessTest() {
log.info(
"Success"
);
}
@Test
@Disabled
(
"Not implemented yet"
)
void
testShowSomething() {
}
As we can see, we can change the display name or disable the method with a comment, using these annotations.
After we have added setup and teardown methods to our test class, we can finally write our first test methods. Let's find out how we can do it.
...