我正在使用Maven的Failsafe插件爲我的Spring Boot應用程序運行集成測試。當我創建了一個簡單的測試,比如這一個:Spring集成測試:無法檢測默認資源位置
@RunWith (SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(App.class)
public class MyTestIT {
@Test
public void test() {
assertTrue (true);
}
}
然後運行mvn verify
我看到的只是Spring應用程序啓動之前以下日誌條目(例如連春啓動橫幅前):
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: [or[email protected]57c758ac, org.springframework.test[email protected]a9cd3b1, org.springframewor[email protected]13e39c73, org.springfra[email protected]64cd705f, org.springframew[email protected]9225652, org.sp[email protected]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
。除此之外,其他一切都與測試無關。
它自己的項目是非常標準的,使用hibernate和mysql和web-mvc作爲休息端點。我在班級通行證上有兩個彈簧安全性配置類。
在main/resources
文件夾中,我有一個application.properties
文件和一個log4j2.xml。沒有test/resources
文件夾,但是當我將主/資源文件夾複製到test/resources
時,上述日誌消息仍然出現。
更新2: 我剛剛創建了一個小示例應用程序試圖重新的問題,似乎提到的日誌輸出開始,我把log4j2.xml
文件到一個文件夾中的資源,一旦出現。我試圖把它放在src/main
或src/test
或兩者具有相同的效果。
看起來很奇怪。如果這是使用默認配置,那麼您可以共享一個重現該問題的項目,對嗎? –
請分享一些更多的細節,如項目結構,pom.xml測試配置文件。因爲當你運行集成測試時,在執行測試用例之前應該運行spring引導。 – Hareesh
你有測試的資源文件夾嗎? – dambros