SpringJUnit4ClassRunner在Spring mvc中对控制器方法进行了集成测试:
@Test
public void testUpdateSuccess() throws Exception {
Integer pageId = 2;
RequestBuilder request = post("/admin/page/update/"+pageId)
.param("id", pageId.toString())
.param("title", "page title 2 edited")
.param("content", "page content 2 edited")
.with(csrf());
mockMvc.perform(request)
.andExpect(status().is3xxRedirection())
.andExpect(MockMvcResultMatchers.flash().attribute("message", "Successfully updated!"));
}
1 - 如何测试以上测试更新的相关数据库行?
2 - 测试数据库是否在上述测试中正确更新是否合适?