SSM配置中单元测试注解@Runwith遇到的坑

版权声明:RemainderTime https://blog.csdn.net/qq_39818325/article/details/84285116

@Runwith测试单元类报错,导包无效

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations ={"classpath:applicationContext.xml"})
public class MapperTest {
}

2,在项目中不能同时导入依赖spring-test  和spring-boot-start-test,不然会冲突,删除任意一个

<!--springboot test-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>2.1.0.RELEASE</version>
    <scope>test</scope>
</dependency>
<!--spring test-->
 <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.0.9.RELEASE</version>
 </dependency>

3,spring中的依赖尽量版本号统一

4,添加junit依赖,这是我的junit版本(我的这个版本没有报错,其他的版本号,试了很多次都报错

    <!--junit-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>compile</scope>
    </dependency>

                                                                                                                                            希望能帮到同样踩到这个抗的同学·······

猜你喜欢

转载自blog.csdn.net/qq_39818325/article/details/84285116
今日推荐