개발 환경 설정 및 툴 사용법

Spring Boot 프로젝트에서 @SpringBootTest , @RunWith 어노테이션 패키지 못 찾을 때 (import 안 될 때)

letsDoDev 2023. 11. 14. 14:15

기존

spring initializer 를 통해 스프링 부트 프로젝트를 생성하였고

스프링 프레임워크 학습을 진행하던 중

테스트를 위해

@RunWith, @SpringBootTest 어노테이션이 import 되지 않는

즉 패키지를 찾지 못하는 문제점을 발견했다.

 

[1. @RunWith 사용을 위해 "추가" 해야 할 dependency - maven 기준 ]

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.12</version>
		</dependency>

버전은 꼭 4.7로 하지 않아도 된다.

추가한 후 maven refresh를 해주면

@RunWith를 import할 수 있게 되었다.

 

[2. @SpringBootTest ]

문제는 간단했다

스프링 이니셜라이저로 스프링 부트를 생성할 때

생성된 <scope>test<scope> 때문에

@SpringBootTest 어노테이션 패키지를 못 찾았던 것

 

제거한 후 

maven refresh를 해주면

''

@SpringBootTest 어노테이션을 import 할 수 있게 되었다.