I've been trying to find a simple all purpose unit test framework for Spring MVC based Rest Services I've written.
I've been searching online and narrowed it down to:
- RestFuse (http://developer.eclipsesource.com/restfuse/)
- Rest Assured (https://github.com/jayway/rest-assured)
- MockMVC (http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-rest-api/)
I like RestFuse because it's mostly annotation based, but rest assured seems to have a easier way of passing parameters and checking responses. And finally being a Spring MVC Rest Service project, I'm wondering if I should just stick with the already established way of testing Rest Services in Spring with MockMVC.
Interested to get any feedback, as well as performance, past experiences and if there's anything else I should take into consideration.
Rest-Assured is gaining acceptance over the other frameworks to test REST services in Java. Having BDD style fluent interface, its easy to read the test scripts also, with minimal learning curve.
I am using this framework for verifying REST services as an end user, and it has been easier to implement test scripts for them. Hence I cannot comment much on Spring MVC part of REST-assured.
However, this blog post gives you more details on RestAssured v2.2 which includes
spring-mock-mvc
module built on top of MockMVC giving BDD style fluent interface flavor through REST assured. The blog post also cautions:When not to use it:
Finally, have a look at REST-Assured spring-mvc-webapp examples in REST-assured codebase, and decide, whether you like to give a try for it and make the best use of both REST-assured and MockMVC frameworks.
The beauty of MockMVC is that it provides a mock servlet container, allowing you to integration-test your REST services without deploying to a web server. I believe that you can still leverage this power when using REST Assured with the
spring-mock-mvc
module.Another framework that I just learned of is Karate. Its author is currently experimenting with a mechanism to allow execution in a mock servlet container (see Peter Thomas' answer to Is there a mechanism for integration testing JAX-RS services without deploying (a la MockMVC)?).