1、加依赖,scope是作用范围,此行表明单元测试只能在test包下使用,若无此行,则作用范围为全部包下。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2、使用前加@Test,加上此注释后,每个方法可独立运行,不用依赖主方法。
若想以此运行全部方法,批量单元测试,用@SpringBootTest注解。

3、不能有参数,也不能有返回值(需void)。
4、后续看参考文章
参考文章:
很详细:
百度安全验证
https://baijiahao.baidu.com/s?id=1773652079123348127&wfr=spider&for=pc
SpringBoot单元测试:依赖管理、注解详解与最佳实践
https://blog.csdn.net/qq_56044032/article/details/128129321
220

被折叠的 条评论
为什么被折叠?



