springboot整合Junit框架
实现步骤:
-
搭建Springboot工程,命名为springboot-test。
完成。 -
引入starter-test起步依赖,快速构建springboot项目自带这个依赖,可以到pom.xml文件中查看,不需要操作
-
编写测试类,如果是MAVEN项目就写到test包下
首先在main/java/com.example.springboottest包下编写一个业务类,方便以后进行测试。先简单写个add()方法
package com.example.springboottest;
import org.springframework.stereotype.Service;
@Service
public class UserService {
public void add(){
System.out.println("add...");
}
}
然后去test/java/com.example.springboottest包下删除原来自动生成的com.example.springboottest.SpringbootTestApplicationTests,新建一个测试用例类UserServiceTest(命名测试哪个类就是类名+Test)