无法导入 assertThat 方法 junit

Cannot import assertThat method junit

我正在使用 hamcrest 和 junit 执行测试,我需要比较具有相同项目但顺序不同的 2 个地图,因此 assertEquals 对我不起作用。 我已经看到了对此的回答,但我无法导入所需的方法。

我是通过以下方式导入的

import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
import static org.junit.Assert.assertThat;

然后我尝试我在答案中看到的下一个内容

assertThat(expectedMap, containsInAnyOrder(receivedMap));

但无法识别方法 assertThat,IDE 向我显示了一个警告,要求我创建方法

您正在导入错误的 assertThat 方法,您想要的是来自 hamcrest 的方法:

import static org.hamcrest.MatcherAssert.assertThat;

Map 未实现 Iterable。因此,方法签名与推断的参数类型 Map<?>Matcher<Iterable<?>>.

不匹配