我正在使用restAssured进行json模式验证。 下面是我的断言脚本: String JsonString = response.asString(); Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath( “quotesschema.json”));
我已将我的quotesschema.json文件放在project / bin文件夹中。
当我运行我的测试脚本时,断言失败并显示以下消息 java.lang.AssertionError:expected []但找到[实际的api响应]
此外,我通过http://json-schema-validator.herokuapp.com/架构验证器验证了我的架构与api响应。
不确定它是否在.son文件中读取我的架构。 下面是我的架构。
{
"type": "object",
"$schema": "http://json-schema.org/draft-03/schema",
"title": "quotes-schema",
"description": "JSON Schema for Quotes",
"properties": {
"result": {
"type": "object",
"properties": {
"Quotes": {
"type": "array",
"properties": {
"DisplaySymbol": {
"type": "string"
},
"Identifier": {
"type": "string"
},
"Exchange": {
"type": "string"
},
"Trade": {
"type": "string"
},
"Date": {
"type": "string"
},
"Change": {
"type": "string"
},
"Bid": {
"type": "string"
},
"BidSize": {
"type": "string"
},
"Ask": {
"type": "string"
},
"AskSize": {
"type": "string"
},
"High": {
"type": "string"
},
"Low": {
"type": "string"
},
"Volume": {
"type": "string"
},
"Open": {
"type": "string"
},
"PreviousClose": {
"type": "string"
},
"High52Week": {
"type": "string"
},
"High52WeekDate": {
"type": "string"
},
"Low52Week": {
"type": "string"
},
"Low52WeekDate": {
"type": "string"
},
"PERatio": {
"type": "string"
},
"MarketCap": {
"type": "string"
},
"SharesOutstanding": {
"type": "string"
},
"RollingEPS": {
"type": "string"
},
"IsDefault": {
"type": "string"
},
"IsIndex": {
"type": "string"
},
"Class": {
"type": "string"
}
}
}
}
}
}
}
答案 0 :(得分:2)
matchesJsonSchemaInClasspath
方法返回JsonSchemaValidator
类,而不是String
。
这就是为什么你的Assert不起作用,比较字符串的原因:
JsonString = response.asString();
Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));
实际使用情况属于body()
方法,如下所述:
get("RESTPATH").then().assertThat().body(matchesJsonSchemaInClasspath("quotesschema.json"));