废话少说!直接开始使用流程
1.首先在pom文件中添加依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2.创建测试类
使用选中要进行测试的类,然后使用快捷键生产对应的类。
3.选中要添加的测试方法
4.ps:如果快捷键没有反应,那么请先添加junit插件!
5.点击确定后,会自动生成对应的test目录和对应的测试类以及方法。然后我们去修改这些方法即可。
6.在测试类上面添加注解
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest
@ActiveProfiles(“local”)
(ps:
@RunWith(SpringJUnit4ClassRunner.class)作用是给junit一个运行环境。
@SpringBootTest作用是读取配置文件加载Spring boot项目
@ActiveProfiles指定运行的配置文件)