programing

스프링 통합 테스트: 기본 리소스 위치를 검색할 수 없습니다.

elecom 2023. 7. 7. 18:35
반응형

스프링 통합 테스트: 기본 리소스 위치를 검색할 수 없습니다.

메이븐의 Failsafe 플러그인으로 Spring Boot 응용 프로그램에 대한 통합 테스트를 실행하고 있습니다.다음과 같은 간단한 테스트를 만들 때:

@RunWith (SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(App.class)
public class MyTestIT {

    @Test
    public void test() {
        assertTrue (true);
    }
}

그리고 뛰어요.mvn verifySpring 응용 프로그램이 시작되기 직전(예: Spring Boot 배너 이전에도) 다음 로그 항목이 표시됩니다.

Running org.....MyTestIT
2016-04-14 13:25:01.166  INFO ???? --- [           main] 
    or.sp.te.co.su.AbstractContextLoader               : 
    Could not detect default resource locations for test class 
    [org....MyTestIT]: no resource found for suffixes
    {-context.xml, Context.groovy}.
2016-04-14 13:25:01.175  INFO ???? --- [           main] 
    or.sp.te.co.su.DefaultTestContextBootstrapper      : 
    Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
2016-04-14 13:25:01.185  INFO ???? --- [           main] 
    or.sp.te.co.su.DefaultTestContextBootstrapper      : Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@57c758ac, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@a9cd3b1, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@13e39c73, org.springframework.test.context.support.DirtiesContextTestExecutionListener@64cd705f, org.springframework.test.context.transaction.TransactionalTestExecutionListener@9225652, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@654f0d9c]

Spring Boot 배너 뒤에 있습니다.그런 다음 테스트가 오류 없이 실행됩니다.이러한 메시지는 INFO 로그 수준으로 인쇄되고 테스트는 정상적으로 실행되지만, 모든 것이 정상이라고 생각하지만 여전히 짜증나는 메시지입니다.그럼 제 구성에 문제가 있는 건가요?제가 이 메시지들에 대해 걱정해야 하나요?

아무 문제가 없었다고 해도, 저는 여전히 그곳에서 무슨 일이 일어나고 있는지, 그리고 메시지가 무엇을 의미하는지 이해하고 싶습니다.

나의maven-failsafe-plugin기본 구성을 사용하고 있을 뿐입니다.App.java으로 주석을 단 단순 클래스일 뿐입니다.@SpringBootApplication.

업데이트 1:

다음은 테스트 플러그인의 구성입니다.

  <plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <!-- Ignore any tests that are marked by the @IntegrationTest annotation of Spring Boot -->
      <excludedGroups>org.springframework.boot.test.IntegrationTest</excludedGroups>
    </configuration>
  </plugin>

  <plugin>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.19.1</version>
    <executions>
      <execution>
        <id>integration-test</id>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

저도 있습니다.spring-boot-starter-test구성된 종속성 및 사용 중spring-boot-devtools게다가 다른 모든 것들은 시험과 관련이 없습니다.

프로젝트 자체는 휴지 상태와 mysql 및 web-mvc를 사용하여 매우 표준적입니다.클래스 패스에 스프링 보안을 위한 구성 수업이 2개 있습니다.

에서main/resources가지고 있는 폴더application.properties파일과 log4j2.xml이 포함됩니다.거기에는 없다test/resources폴더, 그러나 주/리소스 폴더를 복사하는 경우test/resources위의 로그 메시지가 계속 나타납니다.

업데이트 2: 문제를 다시 만들려고 작은 샘플 응용 프로그램을 만들었는데, 문제를 넣자마자 언급된 로그 출력이 나타나기 시작하는 것 같습니다.log4j2.xml파일을 리소스 폴더에 저장합니다.넣어봤어요.src/main또는src/test또는 둘 다 동일한 효과를 가지고 있습니다.

스프링 통합 테스트를 실행할 때의 기본 동작입니다.

참조 문서에서

@ContextConfiguration 주석에서 위치 및 값 특성을 모두 생략하면 TestContext 프레임워크는 기본 XML 리소스 위치를 검색하려고 시도합니다.특히 GenericXmlContextLoader 및 GenericXmlWebContextLoader는 테스트 클래스의 이름을 기반으로 기본 위치를 탐지합니다.클래스 이름이 com.example인 경우.MyTest, GenericXmlContextLoader는 "classpath:com/example/MyTest-context.xml"에서 응용 프로그램 컨텍스트를 로드합니다.

따라서 Maven, log4j 또는 리소스 폴더의 위치/보조와는 아무런 관련이 없습니다.

제가 이 메시지들에 대해 걱정해야 하나요?

전혀, 분명히.

하지만 저는 여전히 이 메시지들이 짜증이 납니다.

검사를 방법을 알 수 (할 수 .)AbstractContextLoaderWARN).

사용할 수 있습니다.AnnotationConfigContextLoader @Configuration.

자세한 내용은 여기를 참조하십시오.

테스트 클래스에 로더에 대한 보다 구체적인 구성으로 주석을 달 수 있으며 Java Config를 사용할 수 있습니다.

다음과 같은 것:

@ContextConfiguration(loader=AnnotationConfigContextLoader.class, classes = ScalaTestConfig.class)

여기서 ScalaTestConfig 클래스에는 다음과 같은 주석이 달립니다.

@Configuration
@ComponentScan(basePackages = {"***", "***"})

아비의 연결고리에 근거합니다.

언급URL : https://stackoverflow.com/questions/36622871/spring-integration-testing-could-not-detect-default-resource-locations

반응형