1.依赖
依赖只需要导入Spring-Boot-starter、Spring-Boot-test(不需要另导入junit依赖)
XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
//web里包含starter
2.测试包结构和源码包结构必须相同(踩了很大的坑才发现的!!!)

3. 注解

注意点:
- 如果要用到Spring容器里的Bean,要在类上加@SpringBootTest注解,不然会报空指针
- 导的是org.junit.jupiter.api.Test,不是Junit的org.junit.Test