...
The firstTest()
method and secondTest()
method have a custom display name and they write a unique string to System.out
.
Code Block |
---|
import org.junit.jupiter.api.*; @DisplayName("JUnit 5 Overview Exampleclass") class JUnit5ExampleTestJUnit5OverviewTest { // Setup @BeforeAll static void beforeAll() { System.out.println("Before\nBefore all test methods \n"); // Some examples of common expensive operations are: // - the creation of a database connection // - the startup of a server. } @BeforeEach void beforeEach() { System.out.println(" Before each test method"); // This is useful when we want to execute some common code before running a test. // - list initialization } // Teardown @AfterEach void afterEach() { System.out.println(" After each test method \n"); } @AfterAll static void afterAll() { System.out.println("After all test methods\n"); } // Added test methods @Test @DisplayName("First test") @Test void firstTest() { System.out.println(" First test method"); } @Test @DisplayName("Second test") void secondTest() { System.out.println(" Second test method"); } } |
We have just written our first test methods. Let's see what happens when we run our unit tests.
...