【问题标题】:Spring MVC Test: How to negate a content testSpring MVC 测试:如何否定内容测试
【发布时间】:2017-12-09 19:23:21
【问题描述】:

如何在 Spring MVC / HamCrest 中否定内容测试,即测试匹配器的否定:

.andExpect(content().string(containsString("StringToNOTExpect")))

【问题讨论】:

    标签: spring model-view-controller hamcrest


    【解决方案1】:

    通过检查 hamcrest CoreMatchers 类并搜索“not”找到了答案:

    import static org.hamcrest.CoreMatchers.not;
    
    ....
    
    .andExpect(content().string(not(containsString("StringToNOTExpect"))))
    

    【讨论】:

      猜你喜欢
      • 2015-05-10
      • 1970-01-01
      • 2020-01-29
      • 2017-04-10
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 2015-04-15
      • 1970-01-01
      相关资源
      最近更新 更多