营销型网站建设工资,网线制作实验报告总结,猪八戒网站开发合同,谷歌google play官网引言
由于spring boot在启动时通常会先行启动一些内置的组件#xff0c;比如tomcat。因此#xff0c;spring boot的测试类一般需要加一些简单的注解。
一、添加依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-…引言
由于spring boot在启动时通常会先行启动一些内置的组件比如tomcat。因此spring boot的测试类一般需要加一些简单的注解。
一、添加依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope
/dependency
二、测试类示例
RunWith标记一个运行期SpringRunner.class它是一个SpringJUnit4ClassRunner的子类名字简短而已未做任何扩展
SpringBootTest注解指定在测试类上用来运行基于Spring Boot的测试。
RunWith(SpringRunner.class)
SpringBootTest
public class UserServiceTest {Autowiredprivate UserService userService;Beforepublic void setUp() throws Exception {// 启动时添加一些逻辑}/*** {role:teacher,teacherName:王建国,jobTitle:教授,gender:男,username:wangjianguo}* br作者 mhtbr * 时间2019年3月17日-下午10:47:07br*/Testpublic void testAddOrUpdateUser() {JSONObject teacher new JSONObject();teacher.put(role, teacher);teacher.put(teacherName, 王力宏);teacher.put(jobTitle, 助理教授);teacher.put(gender, 男);teacher.put(username, wanglihong);SystemResult addOrUpdateUser userService.addOrUpdateUser(teacher);}
}
参考《Spring Boot干货系列十二Spring Boot使用单元测试》