春季方法,我想測試如何使用MockMVC檢查Spring Unittest中的returntype?
@RequestMapping(value="/files", method=RequestMethod.GET)
@ResponseBody
public List<FileListRequest> get() {
return getMainController().getAllFiles();
}
我要放心/文件用列表[FileListRequest]回覆所有來電。怎麼樣?
這是測試應該是的方法。
@Test
public void testGetAll() throws Exception {
this.mockMvc.perform(get("/files").accept("application/json"))
.andExpect(status().isOk())
.andExpect(content().contentType(SOMETHING);
}
我可以簡單地更換SOMETHING還是完全錯誤?
我可以對perform()返回的對象運行assert方法嗎?
你可以使用'JSON path'測試是否響應包含的具體數據 – Pragnani