執行 Rest Assured 程式時出錯
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache
at org.codehaus.groovy.runtime.dgmimpl.NumberNumberMetaMethod.<clinit>(NumberNumberMetaMethod.java:33)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
Response response = RestAssured.get("https://reqres.in/api/users/2");
Assert.assertEquals(response.getStatusCode(), 200);
代碼 Maven 依賴
uj5u.com熱心網友回復:
添加此依賴項并洗掉所有其他放心依賴項。json-path 已經包含在放心依賴中。
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
如果您需要模式驗證器,您可以添加:
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>
確保正確安裝了 JDK/JAVA_HOME 環境變數。上述依賴項應適用于 JDK 8
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/532180.html
