尝试在Rest-Assured工具

时间:2016-11-07 20:54:48

标签: rest-assured json-schema-validator web-api-testing

我们正在尝试验证JSON响应,以查看它是否与放置在Eclipse ClassPath中的模式匹配。这是一个Maven项目,我相信我们已经拥有了所有的依赖项。但是我们总是遇到以下错误:

java.lang.NoClassDefFoundError: com/github/fge/jsonschema/main/JsonSchemaFactory
    at com.jayway.restassured.module.jsv.JsonSchemaValidatorSettings.<init>(JsonSchemaValidatorSettings.java:58)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.createSettings(JsonSchemaValidator.java:277)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.create(JsonSchemaValidator.java:289)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema(JsonSchemaValidator.java:166)
    at com.jayway.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath(JsonSchemaValidator.java:117)
    at com.macys.xapi.ProductServices.TestProductServices.ohGodImDoomed(TestProductServices.java:76)
Caused by: java.lang.ClassNotFoundException: com.github.fge.jsonschema.main.JsonSchemaFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

我们有以下依赖关系:

        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>json-schema-validator</artifactId>
            <version>2.9.0</version>
        </dependency>
        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>jackson-coreutils</artifactId>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>com.github.fge</groupId>
            <artifactId>json-schema-core</artifactId>
            <version>1.2.5</version>
        </dependency>

不确定我们在这里缺少什么 - 有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

Vishnu,只需添加以下依赖项并删除所有上述依赖项。

 <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>3.0.1</version>
</dependency>


 <dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>3.0.1</version>
</dependency>