Hamcrest图书馆中Matcher的问题

prdp8dxp  于 2022-09-21  发布在  Eclipse
关注(0)|答案(1)|浏览(224)

我正在学习Java的学习课程,此人在Hamcrest库中使用contains()方法。代码如下所示

import org.junit.Test;

public class ShipmentTest
{
    private Shipment shipment = new Shipment();

    @Test
    public void shouldAddItems() throws Exception
    {
        shipment.add(door);
        shipment.add(window);

        assertThat(shipment, contains(door, window));
    }

    @Test
    public void shouldReplaceItems() throws Exception
    {
        shipment.add(door);
        shipment.add(window);

        shipment.replace(door, floorPanel);

        assertThat(shipment, contains(floorPanel, window));
    }
}

我使用的是Eclipse,它不能识别contains()方法,因为它是Hamcrest库的一部分。然而,当我尝试实现它时,Eclipse在Hamcrest库中找不到Matchers。它找到MatcherCoreMatchersMatcherAssert,但找不到MatchersMatchers应该使用contains()方法。我已经下载了hamcrest 1.3版的JAR文件,但即使我将其包含在构建路径中,它仍然找不到Matcher。我应该做些什么?

np8igboo

np8igboo1#

我也找不到它,但我只在路径上有org.hamcrest-corejar。然后我意识到Matcher类在org.hamcrest-库jar中!

相关问题