4

We have Json REST API built in Java (spring, gradle).

We would like to do integration testing of our REST API.

We would like to reuse Java Dto objects that are exposed via our REST API while constructing tests - this means that we will have to write tests in java/scala/groovy/etc.

Any suggestions for framework/testing tools that would be easy to use and with as less boilerplate code as possible?

1 Answer 1

3

I would highly recommend rest-driver:

https://github.com/rest-driver/rest-driver

Specifically you'll want to use the server-driver part:

https://github.com/rest-driver/rest-driver/wiki/Server-Driver

There's lots of doc on github for the project but here's an example of a REST API test:

@Test
public void getJsonResponse() {
    Response response = get(BASE_URL + "/things/5", header("Accept", "application/json"));
    assertThat(response, hasStatusCode(200));
}

To re-use your DTOs you can call response.asJSON() and then convert to your DTO via whichever JSON library you are using (Jackson, GSON, etc,.)

Here's a full example of it being used:

https://github.com/scobal/seyren/blob/master/seyren-acceptance-tests/src/test/java/com/seyren/acceptancetests/AlertsAT.java

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.