-
Notifications
You must be signed in to change notification settings - Fork 109
/
JUnit4To5.java
68 lines (55 loc) · 1.9 KB
/
JUnit4To5.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
59
60
61
62
63
64
65
66
67
package com.jetbrains.testing;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
public class JUnit4To5 {
@BeforeAll
public static void beforeClass() throws Exception {
// this is run once before all the tests are run
// use it for more expensive operations that are required by the tests, e.g. setting up connections
System.out.println("JUnit4To5.beforeClass");
}
@BeforeEach
public void before() throws Exception {
// This is run before every test is run
// use it, for example, to set up clean data
System.out.println("JUnit4To5.before");
}
@Test
public void shouldMigrateASimpleTest() {
Assertions.assertEquals("expected", "expected");
}
@Test
@Disabled
public void shouldMigrateIgnoreTestToDisabledTest() {
// This test is Ignored in JUnit 4 and should be Disabled in JUnit 5"
}
@Test
public void shouldStillSupportHamcrestMatchers() {
assertThat(1, equalTo(1));
}
@Test
public void shouldStillSupportAssume() {
Assumptions.assumeTrue(javaVersion() > 8);
// then go ahead and run the rest of the test
}
@AfterEach
public void after() throws Exception {
// this is run after every test
// use it, for example, to clean up after the test
System.out.println("JUnit4To5.after");
}
@AfterAll
public static void afterClass() throws Exception {
// this is run once after all tests are run
// use it for expensive clean up operations, closing connections etc
System.out.println("JUnit4To5.afterClass");
}
//<editor-fold desc="Helper methods">
private int javaVersion() {
// stub method. just used for the example
return 14;
}
//</editor-fold>
}