* def responseJson =
"""
{
"name": "John",
"age": 30,
"cars": {
"car1": "Ford",
"car2": "BMW",
"car3": "Fiat"
},
"bikes": {
"bike1": "b1",
"bike2": "b2",
"bike3": "b3"
}
}
"""
问题:我想比较json的一部分。我试图利用空手道的“包含” dsl,但没有成功。下面的代码参考:
def expectedJson1 =
"""
{
"car1": "#string",
"car2": "#string",
"car3": "#string"
}
"""
* def expectedJson2 =
"""
{
"car1": "#string",
"car2": "#string"
}
"""
* def expectedJson3 =
"""
{
"car1": "#string"
}
"""
* match responseJson contains '#(^expectedJson1)'
* match responseJson contains '#(^expectedJson2)'
* match responseJson contains '#(^expectedJson3)'
我不想使用json路径进行键/值比较,因为实际响应json读取起来相当复杂。因此想随机进行部分匹配。