zoukankan      html  css  js  c++  java
  • spring测试

    今天在用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,好吧,忘了留意 那个注解了!其实这一整套测试还是很严谨的
    
    
  • 相关阅读:
    Less34-Less37 (宽字节注入)
    宽字节注入 Less32-Less33
    Less29(jspstudy)-Less31
    Less26-Less28a
    Less23-Less25a(24--二次注入)
    Less 11-22
    sqli-labs 1-10
    sqli-labs环境搭建与安装
    OSPF与ACL综合实例
    用分治法完成比赛操作
  • 原文地址:https://www.cnblogs.com/minjay/p/6649887.html
Copyright © 2011-2022 走看看