代码之家  ›  专栏  ›  技术社区  ›  clankill3r

方法是(int)未定义

  •  1
  • clankill3r  · 技术社区  · 6 年前

    我使用以下方法导入:

    import static org.junit.Assert.*;

    但在下面这一行:

    assertThat(0, is(1));

    我得到 The method is(int) is undefined for the type AppTest .

    这个方法的名称在英语中很常见,我找不到导入它的位置。

    所以我的问题是,我可以从哪里进口 is (和) not )

    2 回复  |  直到 6 年前
        1
  •  4
  •   GhostCat    6 年前

    你需要

    import static org.hamcrest.Matchers.is;
    

    is() 其他很多伟大的帮手都是 hamcrest Matchers . 当然,您需要以某种方式定义相应的依赖关系。这可能会有点棘手,因为hamcrest有一些核心的匹配器,而且匹配器类的“所有”匹配器。但一旦你发现哪一个对你最有效,你就已经准备好了,一切都很好。

        2
  •  1
  •   デビット    6 年前

    org.assertj.core.api.Assertions 广泛提供测试用例…

    import static org.assertj.core.api.Assertions.*;
    
    assertThat(actual).isEqualTo(expected);
    assertThat(actual).isNotEqualTo(expected);