在进行ssm开发的时候,使用Spring的单元测试,引入了@RunWith和@ContextConfiguration但是不识别
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
1.首先看spring-test与spring-context的jar版本是否一致。
2.junit版本低于4.5不能用@RunWith。 3.单元测试类没有按规范写,所以可以改一下jar包生效的范围
比如在pom.xml中:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.20.RELEASE</version>
<scope>test</scope>
</dependency>
改为:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.20.RELEASE</version>
</dependency>
这里也标错,和上面同理:
SpringJUnit4ClassRunner.class
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
将jar包生效范围扩大,删去 <scope>test</scope>