-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathJunit5Test.java
58 lines (49 loc) · 1.65 KB
/
Junit5Test.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package junit5;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class Junit5Test {
@BeforeAll
static void setup() {
System.out.println("@BeforeAll - executes once before all test methods in this class");
}
@BeforeEach
void init() {
System.out.println("@BeforeEach - executes before each test method in this class");
}
@DisplayName("Single test successful")
@Test
void testSingleSuccessTest() {
System.out.println("in testSingleSuccessTest");
assertEquals(5 + 2, 7);
}
@Test
void shouldThrowException() {
System.out.println("in shouldThrowException");
Throwable exception = assertThrows(UnsupportedOperationException.class, () -> {
throw new UnsupportedOperationException("Not supported");
});
assertEquals("Not supported", exception.getMessage());
}
@Test
void assertThrowsException() {
System.out.println("in assertThrowsException");
String str = null;
assertThrows(IllegalArgumentException.class, () -> {
Integer.valueOf(str);
});
}
@AfterEach
void tearDown() {
System.out.println("@AfterEach - executed after each test method.");
}
@AfterAll
static void done() {
System.out.println("@AfterAll - executed after all test methods.");
}
}