如何在spring mvc集成测试中执行mockMvc后检查受影响的db行

时间:2017-05-06 09:17:50

标签: java spring testing tdd integration-testing

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 - 测试数据库是否在上述测试中正确更新是否合适?

0 个答案:

没有答案