我有一个测试套件:
@RunWith(Suite.class)
@Suite.SuiteClasses({
A.class,
B.class
})
public class TestSuite {
}一堂课:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
public class A {
//nothing
}B级:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@TestPropertySource(value = "classpath:testApplication.properties")
public class B {
//nothing
}现在的问题是@TestPropertySource,testApplication.properties位于test/java/testApplication.properties下,A和B类位于test/java/com.example.MyApp下。如果我用@TestPropertySource测试服评论这一行,运行正常,但如果没有注释,我得到:
java.lang.IllegalStateException:未能加载ApplicationContext 在org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124) at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83) at org.springframework.boot.test.autoconfigure.AutoConfigureReportTestExecutionListener.prepareTestInstance(AutoConfigureReportTestExecutionListener.java:49) at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
properties文件的本地化吗?编辑由is引起的:
导致: java.io.FileNotFoundException:类路径资源testApplication.properties无法打开,因为它不存在
然而,为什么没有找到test/java/testApplication.properties中的位置呢?
发布于 2016-08-28 08:58:58
在试图解决这个问题之后,问题似乎是properties文件必须位于test/java/resources/testApplication.properties中。因此,答案是将属性文件放到resources目录中。
https://stackoverflow.com/questions/39180994
复制相似问题