bay*_*mon 1 testing spring unit-testing spring-mvc spring-boot
这篇博客描述了 Spring Boot 1.4 中的一些测试改进。不幸的是,似乎缺少一些重要信息。什么静态导入需要使用的方法get(),status()并content()从下面的例子吗?
@RunWith(SpringRunner.class)
@WebMvcTest(UserVehicleController.class)
public class UserVehicleControllerTests {
@Autowired
private MockMvc mvc;
@MockBean
private UserVehicleService userVehicleService;
@Test
public void getVehicleShouldReturnMakeAndModel() {
given(this.userVehicleService.getVehicleDetails("sboot"))
.willReturn(new VehicleDetails("Honda", "Civic"));
this.mvc.perform(get("/sboot/vehicle")
.accept(MediaType.TEXT_PLAIN))
.andExpect(status().isOk())
.andExpect(content().string("Honda Civic"));
}
}
Run Code Online (Sandbox Code Playgroud)
我已经发现:
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2691 次 |
| 最近记录: |