相关疑难解决方法(0)

使用Spring和Maven进行测试:applicationContext

似乎这个世界的问题,但我仍然无法找到解决方案..

我正在尝试进行简单的测试:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/applicationContext.xml", "/PersonsPopulateTest-context.xml"})
@Transactional
public class PersonsPopulateTest {
Run Code Online (Sandbox Code Playgroud)

文件位于:

src
   main
      resources
           applicationContext.xml
Run Code Online (Sandbox Code Playgroud)

src        
   test
      resources
          PersonsPopulateTest-context.xml 
Run Code Online (Sandbox Code Playgroud)

因此,在构建这些文件之后,目标/类目标/测试类

但是mvn test命令仍然说:无法加载ApplicationContext

官方文件说什么:

@RunWith(SpringJUnit4ClassRunner.class)
// ApplicationContext will be loaded from "/applicationContext.xml" and "/applicationContext-test.xml"
// in the root of the classpath
@ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-test.xml"})
public class MyTest {
    // class body...
}
Run Code Online (Sandbox Code Playgroud)

我哪里做错了?

谢谢,Vlaidimir

UPDATE.神火的报告:

java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290) …
Run Code Online (Sandbox Code Playgroud)

spring unit-testing maven

33
推荐指数
2
解决办法
9万
查看次数

标签 统计

maven ×1

spring ×1

unit-testing ×1