Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RestAssured vs Mockmvc for unit and integration testing

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?

like image 887
infinite Avatar asked Oct 24 '25 23:10

infinite


1 Answers

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.

like image 83
Jet_C Avatar answered Oct 28 '25 04:10

Jet_C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!