Spring Framework/SpringBoot

[SpringBoot] The import org.springframework.boot.test cannot be resolved

Razelo 2021. 6. 19. 11:00

테스트케이스를 작성하던 도중에 에러를 만났다. 

@Runwith(SpringRunner.class)는 pom.xml에 dependency를 추가해주니 바로 해결됬지만. (이건 검색하면 바로 뜬다.)

 

어째 @SpringBootTest는 에러가 사라지지 않았다. (검색한 내용들도 별로 도움도 안됬다.)

 

The import org.springframework.boot.test cannot be resolved 

 

라고 출력되고 빨간줄이 갔는데, build path에서 junit을 새로 라이브러리 추가해줘도 소용없었고,

clean, refresh도 소용없었다. (이건 사실 매번해도 소용없는거긴하지만 약간 기도같은 느낌... ㅋㅋ )

 

아무튼 dependency만 추가해주는걸 찾아봤는데, 

 

별 소용없었다. 

 

그러다가 이 글을 보게 되었다. 성지같은 느낌.... 

 

https://www.programmersought.com/article/35746544162/

 

The import org.springframework.boot.test cannot be resolved / maven project/Springboot - Programmer Sought

Project scene: When I was learning springboot before, I encountered a problem when trying the unit tutorial according to the tutorial This is the maven dependency required by the tutorial Problem Description: After modifying the pom file as above, I contin

www.programmersought.com

 

나랑 완전히 비슷한 문제를 겪으신 분인것 같은데, 

핵심은 이거다.  pom.xml에 밑에 구문이 있을텐데, 여기서 <scope>test</scope> 를 삭제하는 것이다. 

그리고나서 다시 원래 실행하려던 자바파일로 돌아온뒤에 ctrl shift o 를 누르면 

해당 import가 바로 추가된다. (원래는 ctrl shift o 눌러도 아무것도 추가도 안됬고, 그냥 @SpringBootTest를 확인할 수 없다는 빨간줄만 계속 생겼다. 직접 import 전체를 타이핑해줘도 그 import문에 빨간줄이 가는 상태였다. )

 

그리고 빨간줄도 없어진다. 드디어... 

 

<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>

 

 

Runwith 에러를 없애는건 아래 블로그를 참고했다. 

 

감사합니다. 

 

https://developerntraveler.tistory.com/1

 

[오류, 에러] Spring Junit Test 환경설정 / Class cannot be resolved to a type

코드로 배우는 스프링 웹 프로젝트 (구멍가게 코딩단) 책을 따라하며 실습하던 중 다음과 같은 에러 발생 chapter 02 스프링의 특징과 의존성 주입 (61p) <에러> --> error message : Class cannot be resolved to..

developerntraveler.tistory.com

 

 

반응형