我正在学习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
。它找到Matcher
、CoreMatchers
和MatcherAssert
,但找不到Matchers
,Matchers
应该使用contains()
方法。我已经下载了hamcrest 1.3版的JAR文件,但即使我将其包含在构建路径中,它仍然找不到Matcher
。我应该做些什么?
1条答案
按热度按时间np8igboo1#
我也找不到它,但我只在路径上有org.hamcrest-corejar。然后我意识到Matcher类在org.hamcrest-库jar中!