我发布了一个带有 RestAssured 的 Json,并且在我需要验证所有字段都以正确的值存储在数据库中之后。我的 Json 是:
{
"id": "1",
"name": "name1",
"description": "description1",
"source": "source1",
"target": "target1",
"domain": "PM",
"transformation_rules": [
{
"name": "name2",
"filters": [
{
"object": "object1",
"pattern": "pattern1"
}
],
"operations": [
{
"pattern": "pattern2",
"replacement": "replacement1"
}
]
},
{
"name": "name3",
"filters": [
{
"object": "object2",
"pattern": "pattern2"
}
],
"operations": [
{
"pattern": "pattern3",
"replacement": "replacement2"
},
{
"pattern": "pattern3",
"replacement": "replacement3"
},
{
"pattern": "pattern4",
"replacement": "replacement4"
}
]
}
],
"conflict_policy": "ACCEPT_SOURCE"
}
所以我有 :
responseGet = RestAssured.given().contentType(ContentType.JSON).when().get(urlApi + "/" + id);
我的第一个验证是:
responseGet.then().body("$[0]['id']", equalTo("1"));
为了验证字段“id”是否等于 1,它执行得不好,我更改为:
responseGet.then().body("$.id", equalTo("1"));
和相同的结果--->失败
拜托,你能给我你对测试所有 Json 的建议吗?仅供参考,我尝试申请:https ://github.com/json-path/JsonPath 。
非常感谢您提前,
此致,