1

I have build a REST API Based SMS gateway on Spring boot, along with an extensive testing suite comprising of unit and integration tests for testing the business logic and various layers of the API's architecture. I am now required to create a test which consumes the API call that runs from my localhost under various conditions. My queries are as follows:

  1. Do I need to separately run the Spring Boot application on localhost before I can run the tests that directly consume the API from localhost?

  2. I need to integrate my tests with Travis for Continuous integration. Is it possible to build an integration test which, on being run, starts the Spring application on localhost and directly calls the API URL from localhost for testing its response when different parameters are passed to the URL?

9
  • 1. use jersey WebResource from sun (com.sun.jersey.api.client.WebResource) and 2. mockmvc from (org.springframework.test.web.servlet.MockMvc) :D Commented Jan 15, 2018 at 11:50
  • I am currently looking into RestAssured for creating a test that consumes the API end-point. Would you recommend it, and also have you worked on integrating RestAssured with the build environment of a Spring boot project before? Also, with MockMvc, won't I need to mock the response from the end-point? I have already tested the various components of the API with my unit and integration tests ( controller, service layer, data access layer etc), and now need to consume the API end point without mocking anything. Commented Jan 15, 2018 at 12:26
  • I am using MockMvc now and not see RestAssured yet; On the other hand MockMvc does not mock response data. see this full documentation : docs.spring.io/spring-security/site/docs/current/reference/html/… Commented Jan 15, 2018 at 12:33
  • noted. let me check out the documentation and revert back to you in case i have any queries or when I have been able to successfully build up the required tests. thanks! Commented Jan 15, 2018 at 12:37
  • 1
    Yes, you can see this project. It has only Test for Controller... github.com/yogi21jan/spring-hateos-restassured-demo
    – Yogi
    Commented Jan 15, 2018 at 14:22

1 Answer 1

0

Following from Yogi's comment above, I used RestAssured to build a test suite that directly consumed the API end point running on my localhost.

The following bookmarks helped me understand RestAssured:

For getting a general understanding of how Rest Assured can be used: https://semaphoreci.com/community/tutorials/testing-rest-endpoints-using-rest-assured

The official RestAssured wiki for understanding the API: https://github.com/rest-assured/rest-assured/wiki/Usage#getting-response-data

An example of using RestAssured via Gradle in a Spring project: https://www.blazemeter.com/blog/how-to-extract-values-when-api-testing-with-rest-assured

Using Basic Authentication with Rest Assured: https://www.youtube.com/watch?v=PAyGma2OMFo

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.