JUnit5在未通过测​​试运行程序找到测试的情况下比较两个ArrayLists结果

时间:2019-12-08 16:39:24

标签: java junit5

晚上好!有人可以向我解释为什么我收到此消息吗? :未找到测试运行程序'JUnit5'的测试

@Test在RestaurantMenuTest.class的末尾

这是测试班:

@ExtendWith(MenuEngineParameterResolver.class)
@DisplayName("Test of Restaurant Menu")
class RestaurantMenuTest {

ListOfPurchasedDishes listOfPurchasedDishes = new ListOfPurchasedDishes();

@Test
@DisplayName("test name")
void creatingListArrayWithPurchasedItems() {

    //here I create items the customer wants to purchase
    MenuItem item1 = new MenuItem("PL01", "Pierogi ruskie z cebulką", 28);
    MenuItem item2 = new MenuItem("PL01", "Pierogi ruskie z cebulką", 28);
    MenuItem item3 = new MenuItem("DPL02", "Naleśniki z czekoladą", 12);
    MenuItem item4 = new MenuItem("DPL02", "Naleśniki z czekoladą", 12);
    MenuItem item5 = new MenuItem("AC01", "Czerwone wino wytrawne", 18);
    MenuItem item6 = new MenuItem("AC02", "Czerwone wino półwytrawne", 18);
    MenuItem item7 = new MenuItem("NAC01", "Woda", 10);
    MenuItem item8 = new MenuItem("NAC01", "Woda", 10);
    MenuItem item9 = new MenuItem("NAC06", "Cytryna", 0);
    MenuItem item10 = new MenuItem("NAC07", "Lód", 0);
    MenuItem item11 = new MenuItem("NAC06", "Cytryna", 0);
    MenuItem item12 = new MenuItem("NAC07", "Lód", 0);

    //here I create an exemplary list I would like to get as an output
    List<MenuItem> expectedListOfPurchasedItems = new ArrayList<>();
    expectedListOfPurchasedItems.add(item1);
    expectedListOfPurchasedItems.add(item2);
    expectedListOfPurchasedItems.add(item3);
    expectedListOfPurchasedItems.add(item4);
    expectedListOfPurchasedItems.add(item5);
    expectedListOfPurchasedItems.add(item6);
    expectedListOfPurchasedItems.add(item7);
    expectedListOfPurchasedItems.add(item8);
    expectedListOfPurchasedItems.add(item9);
    expectedListOfPurchasedItems.add(item10);
    expectedListOfPurchasedItems.add(item11);
    expectedListOfPurchasedItems.add(item12);

    //here is the method of the program, the method is shown below in ListOfPurchasedDishes.class
    listOfPurchasedDishes.purchaseDish(item1);
    listOfPurchasedDishes.purchaseDish(item2);
    listOfPurchasedDishes.purchaseDish(item3);
    listOfPurchasedDishes.purchaseDish(item4);
    listOfPurchasedDishes.purchaseDish(item5);
    listOfPurchasedDishes.purchaseDish(item6);
    listOfPurchasedDishes.purchaseDish(item7);
    listOfPurchasedDishes.purchaseDish(item8);
    listOfPurchasedDishes.purchaseDish(item9);
    listOfPurchasedDishes.purchaseDish(item10);
    listOfPurchasedDishes.purchaseDish(item11);
    listOfPurchasedDishes.purchaseDish(item12);

    ArrayList<MenuItem> purchasedItems = listOfPurchasedDishes.listOfPurchasedItems();

    //neither this
    assertEquals(expectedListOfPurchasedItems, purchasedItems);
    //nor this works
    Assert.assertArrayEquals(expectedListOfPurchasedItems.toArray(), purchasedItems.toArray());


}//end of void creatingListArrayWithPurchasedItems
}//end of class RestaurantMenuTest

此处MenuItem具有3个字段:

private String id;
private String name;
private double price;

public MenuItem(String id, String name, double price) {
    this.id = id;
    this.name = name;
    this.price = price;
}

ListOfPurchasedDishes.class看起来像这样

public class ListOfPurchasedDishes {

private ArrayList<MenuItem> purchasedItems = new ArrayList<>();

public ListOfPurchasedDishes() {}

public void purchaseDish(MenuItem menuItem) {
    purchasedItems.add(menuItem);
}//end of public void purchaseDish()

public ArrayList<MenuItem> listOfPurchasedItems() {
    return this.purchasedItems;
}//end of public ArrayList<MenuItem> listOfPurchasedItems()
}//end of public class ListOfPurchasedDishes

我是单元测试的新手,在此示例中,我不知道我在做什么错。有人可以指出我正确的方向吗?谢谢!

0 个答案:

没有答案