带有JSON模式验证的REST保证不起作用 [英] REST Assured with JSON schema validation not working

查看:148
本文介绍了带有JSON模式验证的REST保证不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆