[ERROR][TaskAgile] org.junit... , org.springframework.boot... , mockito... cannot be resolved
2020. 11. 29. 22:20ㆍ개발 관련/ERROR
the type org.hamcrest.matcher cannot be resolved
...
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.boot;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
@WebMvcTest
...
->
the import org.springframework.boot cannot be resolved
the import org.springframework.boot.test cannot be resolved
the import org.mockito cannot be resolved
webMvcTest cannot be resolved
MockBean cannot be resolved
method doThrow~
the import org.junit.jupiter cannot be resolved
ERROR 내용
- 위처럼 junit, springframework.boot.test.*, mockito 를 import 불가
해결 방법
- JUnit4로 할 것인가? JUnit5로 할 것인가?? -> JUnit4로 계속
아래는 JUnit5로 하고 싶을 때 사용
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions> // <- 여기부터 추가
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
참고 사이트 : goddaehee.tistory.com/211
[Junit5] Junit4에서 Junit5으로
안녕하세요. Spring Boot 2.2.x는 Junit5를 기본으로 제공하고 있습니다. 메이저 버전이 바뀌게 되었습니다. 과연 Junit4에서 Junit5로 변화하면서 어떤 부분이 변경되었을까요? 오늘은 Junit5를 사용하는
sabarada.tistory.com
JUnit4로 계속
<scope>test</scope>를 제거했더니 위의 세개 의존성과 관련된 에러는 지워졌다. mockito는 없애도 똑같길래 그냥 냅둠
아까는 test 범위 지웠을 때 변화없었는데.. 왜지?(버전이 바뀌면서 용어도 바뀌었나..?)
<!-- spring test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>5.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.7.22</version>
<scope>test</scope>
</dependency>
참고 사이트 :
모키토 프레임워크(Mockito framework)
Junit 프레임워크에서 많이사용되는 모키토 프레임워크에 대해 알아보자. 차별점 테스트 그 자체에 집중한다. 테스트 스텁을 만드는 것과 검증을 분리시켰다. Mock 만드는 방법을 단일화했다. 테
cornswrold.tistory.com
OKKY | junitClassRunner 에러 질문입니다.
간단한 테스트 클래스 작성시 에러가 나서 질문합니다. RunWith( SpringJUnit4ClassRunner.class) 위 하이라이트 부분에 에러가 나면서 import가 안되요. 그래서 import 문을 강제로 추가하면 그 줄에
okky.kr