带有JSON模式验证的REST保证不起作用 [英] REST Assured with JSON schema validation not working
问题描述
我正在使用Spring Boot和REST确保测试REST API.我正在尝试使用JSON模式验证的示例,但会引发此错误:
I'm working with Spring Boot and REST Assured to test REST APIs. I was trying the example with JSON schema validation but it throws this error:
java.lang.IllegalArgumentException: Schema to use cannot be null
根据文档,该架构应位于类路径中.我的示例架构位于此处.这是我的项目结构和示例架构位置:
According to documentation, the schema should be located in the classpath. My example schema is located there. Here is my project structure and example schema location:
这是我的代码.如果没有模式验证,它就可以正常工作.
Here is my code. Without schema validation it works fine.
given().
contentType("application/json").
when().
get("http://myExample/users").
then().
assertThat().body(matchesJsonSchemaInClasspath("example_schema.json"));
推荐答案
您的模式文件位于rest.resource
包中,但在调用matchesJsonSchemaInClasspath
时并未提及.您要么需要将文件移动到类路径的根目录(例如,将其放在src/test/resources
中),要么将要传递的字符串更改为matchesJsonSchemaInClasspath
.
Your schema file is in the rest.resource
package but you haven't mentioned that when calling matchesJsonSchemaInClasspath
. You either need to move the file to the root of the classpath (put it in src/test/resources
, for example), or change the string you're passing into matchesJsonSchemaInClasspath
.
这篇关于带有JSON模式验证的REST保证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!