Quick Start & FAQS
Qna How to Unit Integration Testing of Rest API Written with Spring

Basically you want to do Integration-Testing as well as Unit-Testing.

You can start the Spring Boot app(or usual Spring app) in a JUnit runner (opens in a new tab), then start firing the tests via JUnit against this app(tomcat/jetty).

But you can go one step further to make/declare them via JSON, so that you can assert the entire response as it is keeping the object/JSON structure intact(using Zerocode lib (opens in a new tab)), without the need of doing repeated assertThat("actual-field1", is(expected-field1)).

Instead of something like below,

HttpResponse response =

aHttpClient.get("https://<host_post_externalized>/users/octocat")

.header("accept", "application/json")

.execute();

User user = response.getUser();

assertThat(response.getStatusCode(), is(200))

assertThat(user.getId(), is(33847731))

assertThat(user.getLogin(), is("octocat"))

assertThat(user.getType(), is("user"))

you just need do this way and keep on adding steps for your subsequent user journey -

{
    "scenarioName": "Invoke the GET api and assert the response",
    "steps": [
        {
            "name": "get_user_details",
            "url": "https://<host_post_externalized>/users/octocat",
            "operation": "GET",
            "assertions": {
                "status": 200,
                "body": {
                    "login" : "octocat",
                    "id" : 33847731,
                    "type" : "User"
                }
            }
        }
    ]
}

See the demo here spring-boot-integration-test (opens in a new tab), which you can clone n run in your local IDE. Instructions are in the README file (opens in a new tab)

Maven dependency needed-

<dependency>
    <groupId>org.jsmart</groupId>
    <artifactId>zerocode-rest-bdd</artifactId>
    <version>1.2.x</version> 
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency>