【问题标题】:The "is" in JUnit 4 assertionsJUnit 4 断言中的“是”
【发布时间】:2010-05-02 14:40:19
【问题描述】:

写作之间有语义上的区别

assertThat(object1, is(equalTo(object2)));

写作

assertThat(object1, equalTo(object2)));

?如果不是,我更喜欢第一个版本,因为它读起来更好。这里还有其他注意事项吗?

【问题讨论】:

    标签: java junit coding-style junit4 assertions


    【解决方案1】:

    文档说明了一切:
    装饰另一个 Matcher,保留其行为,但允许测试更具表现力。
    例如。 assertThat(奶酪,equalTo(臭))
    vs assertThat(cheese, is(equalTo(smelly)))

    http://www.junit.org/apidocs/org/hamcrest/core/Is.html
    换句话说,你在正确的轨道上。

    【讨论】:

      【解决方案2】:

      据我所知,它们是等价的。 “Is”匹配器只是传递给包含的匹配器。它似乎是为了增加可读性,也许还有向后兼容性。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-23
        • 2020-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-12
        相关资源
        最近更新 更多