Skip to content

Commit d47062e

Browse files
committed
Migrate junit4 to junit5
1 parent 8fee85f commit d47062e

File tree

7 files changed

+65
-79
lines changed

7 files changed

+65
-79
lines changed
Lines changed: 46 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,56 @@
11
package com.example.java;
22

33
import com.example.java.component.BookRepository;
4-
import org.junit.After;
5-
import org.junit.Before;
6-
import org.junit.Test;
7-
import org.junit.runner.RunWith;
4+
import org.junit.jupiter.api.*;
85
import org.slf4j.Logger;
96
import org.slf4j.LoggerFactory;
107
import org.springframework.beans.factory.annotation.Autowired;
118
import org.springframework.boot.test.context.SpringBootTest;
12-
import org.springframework.test.context.junit4.SpringRunner;
139

14-
@RunWith(SpringRunner.class)
1510
@SpringBootTest(classes = SpringBootCacheApplication.class)
16-
public class SpringBootCacheApplicationTests {
17-
18-
@Autowired
19-
private BookRepository repository;
20-
21-
private long startTime;
22-
23-
private static final Logger logger = LoggerFactory.getLogger(SpringBootCacheApplicationTests.class);
24-
25-
@Before
26-
public void onBefore() {
27-
startTime = System.currentTimeMillis();
28-
}
29-
30-
@After
31-
public void onAfter() {
32-
logger.info("소요시간: {}ms", System.currentTimeMillis() - startTime);
33-
}
34-
35-
@Test
36-
public void test1() {
37-
repository.getByIsbn("a");
38-
}
39-
40-
@Test
41-
public void test2() {
42-
repository.getByIsbn("a");
43-
}
44-
45-
@Test
46-
public void test3() {
47-
repository.getByIsbn("b");
48-
}
49-
50-
@Test
51-
public void test4() {
52-
repository.getByIsbn("a");
53-
}
54-
55-
@Test
56-
public void test5() {
57-
repository.refresh("a");
58-
repository.getByIsbn("a");
59-
}
11+
@TestMethodOrder(MethodOrderer.Alphanumeric.class)
12+
class SpringBootCacheApplicationTests {
13+
14+
@Autowired
15+
private BookRepository repository;
16+
17+
private long startTime;
18+
19+
private static final Logger logger = LoggerFactory.getLogger(SpringBootCacheApplicationTests.class);
20+
21+
@BeforeEach
22+
void onBefore() {
23+
startTime = System.currentTimeMillis();
24+
}
25+
26+
@AfterEach
27+
void onAfter() {
28+
logger.info("소요시간: {}ms", System.currentTimeMillis() - startTime);
29+
}
30+
31+
@Test
32+
void test1() {
33+
repository.getByIsbn("a");
34+
}
35+
36+
@Test
37+
void test2() {
38+
repository.getByIsbn("a");
39+
}
40+
41+
@Test
42+
void test3() {
43+
repository.getByIsbn("b");
44+
}
45+
46+
@Test
47+
void test4() {
48+
repository.getByIsbn("a");
49+
}
50+
51+
@Test
52+
void test5() {
53+
repository.refresh("a");
54+
repository.getByIsbn("a");
55+
}
6056
}

SpringBootCache/src/test/kotlin/com/example/kotlin/SpringBootCacheApplicationTests.kt

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
package com.example.kotlin
22

33
import com.example.kotlin.component.BookRepository
4-
import org.junit.After
5-
import org.junit.Before
6-
import org.junit.Test
7-
import org.junit.runner.RunWith
4+
import org.junit.jupiter.api.*
85
import org.slf4j.LoggerFactory
96
import org.springframework.beans.factory.annotation.Autowired
107
import org.springframework.boot.test.context.SpringBootTest
11-
import org.springframework.test.context.junit4.SpringRunner
128

13-
@RunWith(SpringRunner::class)
149
@SpringBootTest
10+
@TestMethodOrder(MethodOrderer.Alphanumeric::class)
1511
class SpringBootCacheApplicationTests {
1612

1713
@Autowired
@@ -22,38 +18,38 @@ class SpringBootCacheApplicationTests {
2218
private val logger = LoggerFactory.getLogger(SpringBootCacheApplicationTests::class.java)
2319
}
2420

25-
@Before
26-
fun onBefore() {
21+
@BeforeEach
22+
fun `onBefore`() {
2723
startTime = System.currentTimeMillis()
2824
}
2925

30-
@After
31-
fun onAfter() {
26+
@AfterEach
27+
fun `onAfter`() {
3228
logger.info("소요시간: {}ms", System.currentTimeMillis() - startTime)
3329
}
3430

3531
@Test
36-
fun test1() {
32+
fun `test1`() {
3733
repository.getByIsbn("a")
3834
}
3935

4036
@Test
41-
fun test2() {
37+
fun `test2`() {
4238
repository.getByIsbn("a")
4339
}
4440

4541
@Test
46-
fun test3() {
42+
fun `test3`() {
4743
repository.getByIsbn("b")
4844
}
4945

5046
@Test
51-
fun test4() {
47+
fun `test4`() {
5248
repository.getByIsbn("a")
5349
}
5450

5551
@Test
56-
fun test5() {
52+
fun `test5`() {
5753
repository.refresh("a")
5854
repository.getByIsbn("a")
5955
}

SpringBootConfigurable/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ compileTestKotlin {
4343
}
4444

4545
test {
46-
jvmArgs '-javaagent:libs/spring-instrument-5.1.5.RELEASE.jar'
46+
jvmArgs '-javaagent:libs/spring-instrument-5.2.1.RELEASE.jar'
4747

4848
}
-7.1 KB
Binary file not shown.
7.13 KB
Binary file not shown.

SpringBootConfigurable/src/test/java/com/example/java/AccountTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,17 @@
33
import com.example.java.account.Account;
44
import com.example.java.config.ConfigurableConfig;
55
import com.example.java.config.SecurityConfig;
6-
import org.junit.Test;
7-
import org.junit.runner.RunWith;
6+
import org.junit.jupiter.api.DisplayName;
7+
import org.junit.jupiter.api.Test;
88
import org.springframework.boot.test.context.SpringBootTest;
99
import org.springframework.context.annotation.Import;
10-
import org.springframework.test.context.junit4.SpringRunner;
1110
import org.springframework.transaction.annotation.Transactional;
1211

1312
import javax.persistence.EntityManager;
1413
import javax.persistence.PersistenceContext;
1514

1615
import static org.assertj.core.api.Assertions.assertThat;
1716

18-
@RunWith(SpringRunner.class)
1917
@SpringBootTest
2018
@Transactional
2119
@Import({ConfigurableConfig.class, SecurityConfig.class})
@@ -24,8 +22,9 @@ public class AccountTest {
2422
@PersistenceContext
2523
private EntityManager entityManager;
2624

25+
@DisplayName("Account 비밀번호 리셋 테스트")
2726
@Test
28-
public void test_Account_Configurable_검사() {
27+
public void test() {
2928
// given
3029
Account account = new Account("heowc", "1234");
3130
entityManager.persist(account);

SpringBootConfigurable/src/test/kotlin/com/example/kotlin/AccountTest.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ package com.example.kotlin
33
import com.example.kotlin.account.Account
44
import com.example.kotlin.config.ConfigurableConfig
55
import com.example.kotlin.config.SecurityConfig
6-
import org.junit.Test
7-
import org.junit.runner.RunWith
6+
import org.assertj.core.api.Assertions.assertThat
7+
import org.junit.jupiter.api.Test;
88
import org.springframework.boot.test.context.SpringBootTest
99
import org.springframework.context.annotation.Import
10-
import org.springframework.test.context.junit4.SpringRunner
1110
import org.springframework.transaction.annotation.Transactional
12-
1311
import javax.persistence.EntityManager
1412
import javax.persistence.PersistenceContext
1513

16-
import org.assertj.core.api.Assertions.assertThat
17-
18-
@RunWith(SpringRunner::class)
1914
@SpringBootTest
2015
@Transactional
2116
@Import(ConfigurableConfig::class, SecurityConfig::class)
@@ -25,7 +20,7 @@ class AccountTest {
2520
private lateinit var entityManager: EntityManager
2621

2722
@Test
28-
fun test_Account_Configurable_검사() {
23+
fun `Account 비밀번호 리셋 테스트`() {
2924
// given
3025
val account = Account("heowc", "1234")
3126
entityManager.persist(account)

0 commit comments

Comments
 (0)