1.依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2.@RunWith(SpringRunner.class)
@Test测试类要使用注入的类,比如@Autowired注入的类,自动注入才能生效,不然直接一个NullPointerExecption。
3.org.junit.runners.model.InvalidTestClassError: Invalid test class 异常
@Test 导入包出错,出现这个原因是使用了 org.junit.jupiter.api.Test,应该使用 org.junit.Test