【发布时间】:2016-03-05 13:30:57
【问题描述】:
我要测试的Spring方法
@RequestMapping(value="/files", method=RequestMethod.GET)
@ResponseBody
public List<FileListRequest> get() {
return getMainController().getAllFiles();
}
我想确保所有对 /files 的调用都会以 List[FileListRequest] 响应。怎么样?
这是测试应该采用的方法。
@Test
public void testGetAll() throws Exception {
this.mockMvc.perform(get("/files").accept("application/json"))
.andExpect(status().isOk())
.andExpect(content().contentType(SOMETHING);
}
我可以简单地替换 SOMETHING 还是我完全错了?
我可以对 perform() 返回的对象运行断言方法吗?
【问题讨论】:
-
您可以使用
json path来测试响应是否包含特定数据
标签: spring unit-testing mockmvc