Spring Boot/JUnit5

[JUnit5] 마이그레이션

수수한개발자 2022. 7. 22.

목차

728x90

기본적으로 스프링 부트로 프로젝트를 만들면 spring boot-starter-test 에 JUnit5 가 포함되어 있고 junit-vintage-engine은 빠져있습니다.

 

지금은 공부를 하고 있으니깐 추가해줍니다.

// https://mvnrepository.com/artifact/org.junit.vintage/junit-vintage-engine
testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine'

 

[JUnit5] 마이그레이션

이러면 jupiter가 아닌 그냥 junit @Test 어노테이션이 생깁니다.

 

package me.jisu.javatest;

import org.junit.Before;
import org.junit.Test;

public class StudyJUnit4Test {

    @Before
    public void before() {
        System.out.println("before");
    }

    @Test
    public void createTest() {
        System.out.println("test");
    }

    @Test
    public void createTest2() {
        System.out.println("test2");
    }
}

 

[JUnit5] 마이그레이션

 

이렇게 하고 실행시키면 JUnit5엔진으로 실행이 됩니다.

 

[JUnit5] 마이그레이션

 

JUnit5 가 제공하는 JUnit Platform으로 실행이 됩니다.

 

그리고 패키지에있는 테스트를 다 실행시키면

[JUnit5] 마이그레이션

 

엔진에따라 분리를 해줍니다.

JUnit4로 작성한 테스트와 JUnit5로 나누어서 보여줍니다.

 

junit-vintage-engine을 의존성으로 추가하면, JUnit 5의 junit-platform으로 JUnit 3과 4로 작성된 테스트를 실행할 수 있다.

  • @Rule은 기본적으로 지원하지 않지만, junit-jupiter-migrationsupport 모듈이 제공하는 @EnableRuleMigrationSupport를 사용하면 다음 타입의 Rule을 지원한다.
JUnit 4 JUnit 5
@Category(Class) @Tag(String)
@RunWith, @Rule, @ClassRule @ExtendWith, @RegisterExtension
@Ignore @Disabled
@Before, @After,
@BeforeClass, @AfterClass
@BeforeEach, @AfterEach,
@BeforeAll, @AfterAll

 

728x90

'Spring Boot > JUnit5' 카테고리의 다른 글

[JUnit5] JUnit 5: 확장 모델  (0) 2022.07.22
[Junit5] junit-platform.properties  (0) 2022.07.22
[JUnit5] 테스트 순서  (0) 2022.07.22
[JUnit5] 테스트 인스턴스  (0) 2022.07.22
[JUint5] 테스트 반복하기  (0) 2022.07.22

댓글