SpringBoot(十)--整合单元测试

junit

依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>

然后在测试包的测试类上添加:

@SpringbootTest(classes={xxxapplication.class})//里面放启动器的类
@RunWith (SpingJUnit4ClassRunner.class) //启动器

SpingJUnit4ClassRunner.class:让junit与spring环境进行整合
@SpringbootTest(classes={xxxapplication.class})有两层含义:
1:当前类为SpringBoot的测试类
2:加载SpringBoot启动类,启动Springboot项目

其他操作就跟mvc的操作一样的

原创文章 25 获赞 10 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_42195162/article/details/95107440
今日推荐