标签:servlet boot service 注意 window blank image figure 注解
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<1> 如果使用IntelliJ IDEA,可以使用快捷键直接生成:
<2> 自己手动去创建

<1> 在测试类上加入@RunWith(SpringRunner.class) 与@SpringBootTest 注解,
<2> 编写测试方法并添加@Test注解

<1> 在pom.xml中引入依赖(与上相同)
<2> 在测试类上加入@RunWith(SpringRunner.class) 与 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 注解
<3> 使用TestRestTemplate对象测试

<1> 在pom.xml中引入依赖(与上相同)
<2> 在测试类上加入@RunWith(SpringRunner.class) 与 @WebMvcTest 注解
<3> 使用MockMvc对象测试
仍然测试UserController类
错误信息:found multiple declarations of @BootstrapWith
一个是:(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper)
一个是:(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper)
例如:@WebMvcTest(UserController.class) 只会加载UserController类
本文转自:https://www.jianshu.com/p/3a82791b9d3e?from=singlemessage
标签:servlet boot service 注意 window blank image figure 注解
原文地址:https://www.cnblogs.com/nizuimeiabc1/p/12173927.html