1

I imported using the following:

import static org.junit.Assert.*;

But on the following line:

assertThat(0, is(1));

I get The method is(int) is undefined for the type AppTest.

The name of this method is so common in the English language that I can not find where to import this.

So my question is, where can I import is (and not).

4

2 回答 2

4

你需要

import static org.hamcrest.Matchers.is;

is()其他很多大帮手都是hamcrest Matchers。当然,您需要以某种方式定义相应的依赖项。它可能会有点棘手,因为 hamcrest 有一些核心匹配器,并且匹配器类具有“所有”匹配器。但是一旦你确定哪一个最适合你,你就准备好了,一切都很好。

于 2019-01-28T20:26:23.093 回答
1

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

import static org.assertj.core.api.Assertions.*;

assertThat(actual).isEqualTo(expected);
assertThat(actual).isNotEqualTo(expected);
于 2019-01-29T02:46:31.903 回答