今天在用spring做集成测试的时候,代码如下
@Test
@DatabaseSetup({"userData.xml", "emptyUserMailTemplateData.xml","systemMailTemplateData.xml"})
@ExpectedDatabase(value = "saveUserMailTemplateExpected.xml", assertionMode = DatabaseAssertionMode.NON_STRICT)
public void createNewTemplateShouldAddTemplateAndRedirectSuccessView() throws Exception {
mockMvc.perform(post("/user/template/add").with(user(securityUser()))
.param("name", "aaa")
.param("approveStatus", "4")
.param("template.subject", "test template")
.param("template.body", "test template")
.param("systemTemplateId",new String[]{"1"})
.sessionAttr("template", new UserMailTemplate()))
.andExpect(status().isFound())
.andExpect(view().name("redirect:/user/template/create_or_update_success"));
}
测试一直失败,可是仅看controller层和这里的测试方法是没有问题的,但是一直测试不成功,显示 expect1 actual 4,原来是
@ExpectedDatabase
这个注释的原因,因为
saveUserMailTemplateExpected.xml里面的数据该字段为1,而我存的时候是设为4,好吧,忘了留意 那个注解了!其实这一整套测试还是很严谨的
undefined
Original: https://www.cnblogs.com/minjay/p/6649887.html
Author: minjay26
Title: spring测试
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/579862/
转载文章受原作者版权保护。转载请注明原作者出处!