4

I am asked to choose one and the best from these two for unit and integration tests-

1. RestAssured
2. Mockmvc

The application is in Spring and Spring Boot. I have read many blogs and no clear distinction is given or I couldn't find one. For rest assured, its neat and clean code and BDD style that makes it more readable. But doesn't sound a convincing point. Some of the tests are written using Mockmvc and I am trying to write the same in RestAssured to compare the same.

I know this may sound a theoretical question but I am unable to get points in favor of one and suggest which one is better and why. Looks like a choice of flavor to me. Any views and suggestions?

a p
  • 1,121
  • 6
  • 26
  • 51
  • Possible duplicate of [RestFuse vs Rest Assured vs MockMVC Rest Service Unit Test Framework](https://stackoverflow.com/questions/34646021/restfuse-vs-rest-assured-vs-mockmvc-rest-service-unit-test-framework) – Mahesh_Loya Mar 13 '18 at 13:26

1 Answers1

4

You would choose MockMvc for web layer testing. These tests will allow you to validate your controller classes properly handle respective HTTP requests. Since these are practically fine grained controller unit tests, you can additionally include them as part of your apps’ code coverage percentage with tools like JaCoCo. On a side note, these tests will likely run faster than integration tests since they won’t require the web server to run on.

RestAssured is used for integration testing in your Spring Boot app. When it comes to RESTful based API integration testing and validation, RestAssured offers convenient methods to create and execute your HTTP calls with custom headers, auth, content types, query parameters, payload content, cookies, etc.

To aid your comparison check out this article - Testing Spring Boot RESTful APIs using MockMvc/Mockito, Test RestTemplate and RestAssured - it has a good explanation and robust examples on the usage for RestAssured and MockMvc.

Jet_C
  • 644
  • 9
  • 12