restAssured json 架构验证 - 读取 JSON 架构文件断言失败



>我正在使用restAssure进行我的json架构验证。下面是我的断言脚本:String JsonString = response.asString();Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));

我已经将我的 quotesschema.json 文件放在项目/bin 文件夹中。

当我运行测试脚本时,断言失败并显示以下消息java.lang.AssertionError: 预期 [] 但找到 [实际 API 响应]

此外,我通过模式验证器根据 api 响应验证了我的架构 http://json-schema-validator.herokuapp.com/。

不确定它是否在 .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"
                                    }
                            }
                        }
                    }
                }
}
}

matchesJsonSchemaInClasspath方法返回JsonSchemaValidator类而不是String

这就是为什么你的断言不起作用,其中比较字符串:

JsonString = response.asString();
Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));   

实际用法body()方法内部,如下所述:

get("RESTPATH").then().assertThat().body(matchesJsonSchemaInClasspath("quotesschema.json"));

最新更新