【问题标题】:Hamcrest: How to test for multiple properties of an objectHamcrest:如何测试对象的多个属性
【发布时间】:2018-08-13 18:08:13
【问题描述】:
rules=[{type:"path", value:"abc"},{type:"cookie", value:"xyz"}, ...]

我想查找数组是否包含具有属性的对象(type=pathvalue=abc

我尝试过这样的事情: assertThat(rules, hasItem(hasProperty("type", equals("path"))));

但我没有找到组合两个hasProperty 方法的方法。谁能帮帮我

【问题讨论】:

    标签: java assert hamcrest


    【解决方案1】:

    以下将尝试将allOf() 检查中的每个匹配器应用于rules 中的每个项目:

        assertThat(rules,
                hasItem(allOf(hasProperty("type", equalTo("path")),
                        hasProperty("value", equalTo("abc")))));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 2017-01-14
      • 1970-01-01
      • 2015-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-03-24
      相关资源
      最近更新 更多