언어·프레임워크/Spring Boot

[Spring Boot][Trouble Shooting] gradlew test 실패

DandyNow 2022. 9. 12. 22:39
728x90
반응형
gradlew test

위 명령을 실행해 build test를 진행했는데 아래와 같이 에러가 발생했다.

C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>gradlew test

> Task :test

SpringWebserviceApplicationTests > contextLoads() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
        Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException at DefaultListableBeanFactory.java:1004

1 test completed, 1 failed

> Task :test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///C:/Users/J/Documents/GitHub/spring-boot-webservice-java11/spring-webservice/build/reports/tests/test/index.html

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s
5 actionable tasks: 2 executed, 3 up-to-date

C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>

 

원인은 src\test\resources\application.properties에 spring.main.allow-bean-definition-overriding=true 설정이 추가되어 있지 않았기 때문이었다.

spring.main.allow-bean-definition-overriding=true

위 설정을 src\test\resources\application.properties에 추가하여 문제를 해결했다.

 

✎ 참고: https://eodevelop.tistory.com/29

 

org.springframework.beans.factory.support.BeanDefinitionOverrideException 에러

SpringBoot로 새로운 프로젝트 환경을 구축하던 중 org.springframework.beans.factory.support.BeanDefinitionOverrideException 와 같은 에러를 만났다. 일단 해결책 부터 얘기하면 application.properties 파일..

eodevelop.tistory.com

 


다시 gradlew test로 build test를 진행했는데 다음과 같은 에러가 발생했다.

C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>gradlew test

> Task :compileTestJava FAILED
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:8: error: package org.junit does not exist
import org.junit.After;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:9: error: package org.junit does not exist
import org.junit.Test;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:10: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:15: error: cannot find symbol
@RunWith(SpringRunner.class)
 ^
  symbol: class RunWith
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\dto\HelloResponseDtoTest.java:3: error: package org.junit does not exist
import org.junit.Test;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\HelloControllerTest.java:10: error: package org.junit does not exist
import org.junit.Test;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\HelloControllerTest.java:11: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\HelloControllerTest.java:22: error: cannot find symbol
@RunWith(SpringRunner.class) // 테스트를 진행할 때 JUnint에 내장된 실행자 외에 다른 실행자를 실행. 스프링 부트 테스트와 JUnit 사이 연결자 역할
 ^
  symbol: class RunWith
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\IndexControllerTest.java:3: error: package org.junit does not exist
import org.junit.Test;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\IndexControllerTest.java:4: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\IndexControllerTest.java:12: error: cannot find symbol
@RunWith(SpringRunner.class)
 ^
  symbol: class RunWith
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:11: error: package org.junit does not exist
import org.junit.After;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:12: error: package org.junit does not exist
import org.junit.Before;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:13: error: package org.junit does not exist
import org.junit.Test;
                ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:14: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
                       ^
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:32: error: cannot find symbol
@RunWith(SpringRunner.class)
 ^
  symbol: class RunWith
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:22: error: cannot find symbol
        @After // Junit에서 단위 테스트가 끝날 때마다 수행되는 메서드 지정
         ^
  symbol:   class After
  location: class PostsRepositoryTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:27: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class PostsRepositoryTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\domain\posts\PostsRepositoryTest.java:48: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class PostsRepositoryTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\dto\HelloResponseDtoTest.java:8: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class HelloResponseDtoTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\HelloControllerTest.java:30: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class HelloControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\HelloControllerTest.java:40: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class HelloControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\IndexControllerTest.java:19: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class IndexControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:50: error: cannot find symbol
        @Before // 매번 테스트가 시작되기 전에 MockMvc 인스턴스를 생성
         ^
  symbol:   class Before
  location: class PostsApiControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:58: error: cannot find symbol
        @After
         ^
  symbol:   class After
  location: class PostsApiControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:63: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class PostsApiControllerTest
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java:90: error: cannot find symbol
        @Test
         ^
  symbol:   class Test
  location: class PostsApiControllerTest
Note: C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
27 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileTestJava'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s
3 actionable tasks: 1 executed, 2 up-to-date

C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>

 

testImplementation 'junit:junit:4.13'

JUnit 4 설정이 되어 있지 않아서였기 때문에 build.gradle에 위 설정을 추가하여 문제를 해결하였다.

 


모든 에러를 해결하였고 build test가 아래와 같이 성공적으로 끝났다!

C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>gradlew test

> Task :compileJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :compileTestJava
Note: C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice\src\test\java\com\tistory\postforty\book\springboot\web\PostsApiControllerTest.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :test
2022-09-12 22:08:11.892  INFO 11608 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2022-09-12 22:08:11.893  INFO 11608 --- [ionShutdownHook] .SchemaDropperImpl$DelayedDropActionImpl : HHH000477: Starting delayed evictData of schema as part of SessionFactory shut-down'
Hibernate: drop table if exists posts
Hibernate: drop table if exists user
2022-09-12 22:08:11.899  INFO 11608 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2022-09-12 22:08:11.905  INFO 11608 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

BUILD SUCCESSFUL in 25s
5 actionable tasks: 5 executed
C:\Users\J\Documents\GitHub\spring-boot-webservice-java11\spring-webservice>

 

728x90
반응형