在编写Springboot时,测试类运行报错,为什么?要怎么解决啊😭
jar包依赖问题,重新导入下maven依赖包试试
包没找到,
@MapperScan("com.test.xsj.mapper") //有使用数据库的时候加上此注解
@SpringBootTest //使用这个注解
能看看你的pom依赖?
测试类使用@SpringBootTest注解
springboot 测试要使用 @SpringBootTest
```java
package com.julong;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class ZookeeperWebUiApplicationTest {
@Test
public void zookeeperTest() {
}
}
```
修改pom文件:
使用springboot启动器创建的工程的pom中默认会带测试启动器spring-boot-starter-test;
spring-boot-starter-test默认依赖Junit5(JUnit Platform + JUnit Jupiter + JUnit Vintage);
需要排除Junit5相关的依赖包:排除junit-jupiter-api,然后再加入Junit4的依赖