[SpringBoot] JUnit 4 적용하기

dondonee·2024년 3월 26일
0

SpringBoot 3에서 JUnit 4 적용하기

SpringBoot 3에서는 기본적으로 JUnit 5를 사용한다. 현재 프로젝트를 스프링부트 3.1 버전으로 빌드했더니 JUnit 5의 기본 엔진인 junit-jupiter-engine:5.9.3이 설치되었다.

JUnit 4 테스트를 사용하기 위해서는 JUnit 빈티지 엔진을 추가해야 한다. 빈티지 엔진은 JUnit 3, JUnit 4와의 하위 호환을 제공하는 JUnit 5의 엔진이다.



JUnit 4 의존성 추가

다음과 같이 의존성을 추가한다.


testImplementation("org.junit.vintage:junit-vintage-engine") {
 exclude group: "org.hamcrest", module: "hamcrest-core"
}

build.gradle의 경우 위와 같이 추가한다.


<dependency>
    <groupId>org.junit.vintage</groupId>
    <artifactId>junit-vintage-engine</artifactId>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

pom.xml을 사용하는 경우 위와 같이 추가한다.


hamcrest-core 모듈을 제외하는 것은 spring-boot-starter-test를 통해 이미 설치되어 있기 때문이다.




🔗 References

0개의 댓글