说明
单元测试的基本用法,最主要就是@runwith(springrunner.class)记不住
代码
引入依赖
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.2.RELEASE</version><relativePath/></parent><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency>
在SpringBoot中的代码
@SpringBootTest@RunWith(SpringRunner.class)class CommunitystudyApplicationTests {@AutowiredUserService userService;@Testvoid contextLoads() {System.out.println("测试代码");}}
注意
1.重要的依赖就是spring-boot-starter-test
