编程语言
首页 > 编程语言> > java – REST确保JSON模式验证不起作用

java – REST确保JSON模式验证不起作用

作者:互联网

我正在使用Spring Boot和REST Assured来测试REST API.我正在尝试使用JSON模式验证的示例,但它会抛出此错误:

java.lang.IllegalArgumentException: Schema to use cannot be null

根据文档,架构应该是located in the classpath.我的示例架构位于那里.这是我的项目结构和示例模式位置:

project structure

这是我的代码.没有架构验证它工作正常.

given().
    contentType("application/json").
when().
    get("http://myExample/users").
then().
    assertThat().body(matchesJsonSchemaInClasspath("example_schema.json"));

解决方法:

您的模式文件位于rest.resource包中,但在调用matchesJsonSchemaInClasspath时您没有提到过.您需要将文件移动到类路径的根目录(例如,将其放在src / test / resources中),或者更改您传递给matchesJsonSchemaInClasspath的字符串.

标签:java,maven,spring-boot-2,rest-assured,json-schema-validator
来源: https://codeday.me/bug/20190528/1168703.html