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"));
Your schema file is in the
rest.resource
package but you haven't mentioned that when callingmatchesJsonSchemaInClasspath
. You either need to move the file to the root of the classpath (put it insrc/test/resources
, for example), or change the string you're passing intomatchesJsonSchemaInClasspath
.