Error

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests

ewok 2023. 3. 14. 22:00

문제

테스트를 작성하면서 아래와 같은 오류가 발생했다.

 

아래는 작성한 테스트이다.

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(SpringExtension.class)
@WebMvcTest(controllers = HomeController.class)
public class HomeControllerTest {

    @Autowired
    private MockMvc mvc;

    @Test
    public void hello가_리턴된다() throws Exception {
        String hello = "hello";

        mvc.perform(get("/hello"))
                .andExpect(status().isOk())
                .andExpect(content().string(hello));
    }
}

 

 

build.gradle

...

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    testImplementation('org.springframework.boot:spring-boot-starter-test')

    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}

test {
    useJUnitPlatform()
}

 

 

해결

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'

위 두 코드를 제거했더니 문제가 해결 되었다.

https://github.com/jojoldu/freelec-springboot2-webservice/issues/585#issuecomment-818407043

 

[오류] p.63 HelloControllerTest 오류 · Issue #585 · jojoldu/freelec-springboot2-webservice

기존에 올라온 질문이 아닌지 먼저 검색해주세요! 가장 자주 나온 제보 P.105 @PutMapping("/api/v1/posts") P.111 Posts.update 어떤 오류인가요? 오류설명: HelloControllerTest 테스트 코드 실행시 Test 실패 메세지

github.com

이미 spring-boot-starter-test에 junit이 포함되어 있는데 별도로 junit을 추가해서 중복됐기 때문인 것 같다.

 

종속성을 제거하고 보니

5.8.1이 아닌 5.7.0으로 바뀌었다. 기본적으로 포함된 5.7.0이 있는데 5.8.1이 들어와 두 개가 충돌된 것 같다.

댓글수0