Spring Test Context Framework

时间:2013-03-22 10:16:26

标签: spring testing junit

我有一个使用Test Context Framework的项目。

我使用Run As执行测试 - > JUnit测试,但它显示initializationError();

堆栈追踪:

java.lang.NoSuchFieldError: NULL
    at org.junit.runners.ParentRunner.<init>(ParentRunner.java:57)
    at org.junit.runners.BlockJUnit4ClassRunner.<init>(BlockJUnit4ClassRunner.java:57)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:104)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.junit.internal.requests.ClassRequest.buildRunner(ClassRequest.java:33)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:28)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

测试类:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:WEB-INF/spring-servlet.xml")
public class PoolRuleMappingDaoTest {

     @Autowired
     private PoolRuleDao poolRuleDao;

     public PoolRuleMappingDaoTest() {

     }

     @Before
     public void setup() {

     }

     @After
     public void tearDown() {

     }

     @Test
     public void getCountryTest() { 

     }      
}

如何运行测试?

1 个答案:

答案 0 :(得分:4)

看起来您可能正在运行不受支持的JUnit版本。

您使用的是什么版本的spring-test

您使用的是什么版本的junit

仅供参考:Spring 2.5需要JUnit 4.4; Spring 3.0及更高版本需要JUnit 4.5或更高版本。