REST Assured with JSON schema validation not worki

2019-04-09 22:06发布

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:

project structure

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"));

1条回答
SAY GOODBYE
2楼-- · 2019-04-09 22:46

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.

查看更多
登录 后发表回答