当我尝试使用放心的框架执行脚本时出现错误。请指导我解决同样的问题。我用下面的 jar

Java version - 8
rest-assured-2.8.0
json-path-2.8.0
hamcrest-all-1.3
commons-lang3-3.0
json-schema-validator-2.2.0



>FAILED: foo
    java.lang.NoClassDefFoundError: io/restassured/mapper/factory/GsonObjectMapperFactory
        at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
        at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
        at practice.GetRequest.foo(GetRequest.java:12)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
        at org.testng.TestRunner.privateRun(TestRunner.java:744)
        at org.testng.TestRunner.run(TestRunner.java:602)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
        at org.testng.TestNG.runSuites(TestNG.java:1144)
        at org.testng.TestNG.run(TestNG.java:1115)
        at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
        at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
        at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:76)
    Caused by: java.lang.ClassNotFoundException: io.restassured.mapper.factory.GsonObjectMapperFactory
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 28 more


    ===============================================
        Default test
        Tests run: 1, Failures: 1, Skips: 0
    ===============================================


    ===============================================
    Default suite
    Total tests run: 1, Failures: 1, Skips: 0
    ===============================================

最佳答案

造成这种情况的根本原因是可以放心使用的*ObjectMapperFactory软件包名称发生更改,例如在3.x4.x版本之间进行更改。

对于在release of rest-assured 4.0.0之后遇到此问题的任何人,此问题都可能在Spring Boot项目中出现-由rest-assured与其对spring-boot-dependencies bom中的json-pathxml-path的传递依赖项之间的版本不匹配引起。

如果指定依赖项io.rest-assured:rest-assured:4.0.0,则还需要显式包括io.rest-assured:json-path:4.0.0io.rest-assured:xml-path:4.0.0,否则spring-boot-dependencies将使用旧的* ObjectMapperFactory软件包名称引入3.1.1版本。

关于rest-assured - java.lang.NoClassDefFoundError:io/restassured/mapper/factory/GsonObjectMapperFactory,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44993615/

10-11 16:58