【问题标题】:How to compare two json objects using testng如何使用 testng 比较两个 json 对象
【发布时间】:2014-11-15 09:29:56
【问题描述】:

这里我有 2 个与

数据相同的 JSONObjects
{
  "userId": 1,
  "id": 1,
  "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
  "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}

我想使用 TestNG 比较 2 个对象。

我尝试了以下方法,但结果错误。

Assert.assertEquals(actualObject, ExpectedObject);

谁能帮我解决这个问题?

【问题讨论】:

    标签: json testng jira-rest-api jsonassert


    【解决方案1】:

    我会使用 JSONAssert - https://github.com/skyscreamer/JSONassert

    JSONObject data = getRESTData("/friends/367.json");
    String expected = "{friends:[{id:123,name:\"Corby Page\"},{id:456,name:\"Carter Page\"}]}";
    JSONAssert.assertEquals(expected, data, false);
    

    【讨论】:

    • JSONAssert 不支持 TestNG,它只支持 Junit
    • 断言库可以与任何框架一起使用。
    猜你喜欢
    • 2019-03-09
    • 2016-09-05
    • 1970-01-01
    • 2017-11-29
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多