[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
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>
참고 사이트 :