-1

getting an error while executing the Rest Assured program

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

Code Maven Dependency

1 Answers1

0

Add this dependency and remove all other rest assured dependencies. json-path is already included in rest-assured dependency.

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>5.2.0</version>
    <scope>test</scope>
</dependency>

If you need schema validator you can add:

<!-- 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>

Make sure you have JDK/JAVA_HOME env variable properly installed. The abouve depedencies should work with JDK 8+

Alex Karamfilov
  • 634
  • 1
  • 6
  • 12
  • Getting a new error saying this "SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. " – Ravi Ranjan Nov 12 '22 at 14:13
  • This is warning I believe. You should be able to send request now. You can log it by using this RestAssured.given().log().all().when().get("https://reqres.in/api/users/2"); – Alex Karamfilov Nov 12 '22 at 14:17
  • You can fix the slf4j warning by adding dependencies : org.slf4j slf4j-api 1.7.5 org.slf4j slf4j-log4j12 1.7.5 – Alex Karamfilov Nov 12 '22 at 14:19