3

在这里,我有 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);

谁可以帮我这个事 ?

4

1 回答 1

0

我会使用 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);
于 2014-11-15T09:41:44.497 回答