본문으로 바로가기

[JUnit4][Error] 실행 시 initailizationError 해결 방법

category JAVA/JUnit 2022. 2. 19. 00:42

에러

JUnit 실행 시 initailizationError 발생

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

원인

1. ControllerTest에 @ContextConfiguration 선언을 안 한 경우.

2. classes 선언을 main 폴더 아래의 Application 이름으로 선언하지 않은 경우.

   (test 폴더 아래 Application 에러로 선언한 경우 에러 발생)

 

해결

@ContextConfiguration(classes = ExampleApplication.class)
public class ExampleControllerTest {
	// content
}

 

위와 같이 @ContextConfiguration 선언하여 해결해주었다.

 

후기

initailizationError 를 발생하는 경우 중 library를 추가 하지 않은 경우도 있는 것 같다.

참고하시길..

https://gabrielyj.tistory.com/211

 

[스프링/에러] initializationError에러 / Method 'initializationError' not found. Opening the test class.

스프링 프로젝트 JUnit 테스트에서 Method 'initializationError' not found. Opening the test class. 가 발생하는 원인은, 프로젝트에 JUnit 라이브러리가 추가되지 않았기 때문입니다. 아래의 과정을 거쳐 라..

gabrielyj.tistory.com