簡體   English   中英

我的 TestNG 斷言失敗了。 有人可以幫忙嗎? 我在這里做的錯誤是什么

[英]My TestNG assertion is failing. Can someone help here please. What is the mistake I am doing here

String response = given().contentType(contentType).body(Payload.MultipleMSIDS()).when().post(baseURI).thenReturn().asString();

    System.out.println(response);

    XmlPath xml = new XmlPath(response);


    List<String> actualList = xml.getList("svc_result.slia.pos.msid");

    System.out.println(actualList);

    String[] expectedOutput = new String[]{"[11, 12, 13]",
            "[13, 12, 11]","[11, 13, 12]",
            "[13, 11, 12]","[12, 13, 11]",
            "[12, 11, 13]"};

    List<String> expectedOutputList = Arrays.asList(expectedOutput);

    System.out.println(expectedOutputList);

    Assert.assertTrue(expectedOutputList.Contains(actualList));

java.lang.AssertionError: 預期:true 實際:false [11, 12, 13] - actualList

[[11, 12, 13],[13, 12, 11],[11, 13, 12],[13, 11, 12],[12, 13, 11],[12,

11, 13]] - 預期輸出列表

你得到錯誤是因為當你使用contains你是在詢問一個列表是否包含一個對象。 在您的特定情況下,您詢問expectedOutputList如果它包含另一個List ,它是一個String List 由於它根本沒有List對象(只有String對象),因此它返回 false。

如果您想測試您的列表是否包含另一個列表的元素,您需要使用containsAll方法,例如:

expectedOutputList.containsAll(actualList)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM