2
votes

I have a REST API built with Spring Boot.

I am attempting to use Rest-Assured test framework, however I can't seem to get it to work.

I am using the guide from Here

get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));

And have added the dependencies to my maven project.

<dependency>
      <groupId>com.jayway.restassured</groupId>
      <artifactId>rest-assured</artifactId>
      <version>2.9.0</version>
      <scope>test</scope>
</dependency>

However, It doesn't seem to import the required classes and just prompts me to create a new "get()" method.

My Test class:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
@WebIntegrationTest
public class DemoControllerTest  {

    @Test
    public void test() {
        get("/lotto").then().assertThat().body("lotto.lottoId", equalTo(5));
    }

}

What am I missing?

2
Don't know much about rest assured. But shouldn't there be imports in Java class to use these methods. - Himanshu Bhardwaj
I'm using eclipse to manage the imports. It's not suggesting anything. - Yonkee

2 Answers

3
votes

What am I missing?

A simple static import, that's missing! In order to resolve the get static method, just use the following static import:

import static com.jayway.restassured.RestAssured.get;
2
votes

I had similar issue. What I did (using new version 3.0.2):

import io.restassured.RestAssured.*;
import io.restassured.matcher.RestAssuredMatchers.*;
import org.hamcrest.Matchers.*;

Instead of:

import static io.restassured.RestAssured.*;
import static io.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;

So I had same issue couldnt find the methods ...