RestFuse vs Rest Assured vs MockMVC Rest Service 单元测试框架 [英] RestFuse vs Rest Assured vs MockMVC Rest Service Unit Test Framework

查看:60
本文介绍了RestFuse vs Rest Assured vs MockMVC Rest Service 单元测试框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图为我编写的基于 Spring MVC 的 Rest 服务找到一个简单的通用单元测试框架.

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 因为它主要是基于注释的,但放心似乎有更简单的方法来传递参数和检查响应.最后是一个 Spring MVC Rest Service 项目,我想知道我是否应该坚持使用 MockMVC 在 Spring 中测试 Rest 服务的已经建立的方法.

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 在 Java 中测试 REST 服务比其他框架更受欢迎.具有 BDD 风格的流畅界面,易于阅读测试脚本,并且学习曲线极小.

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.

我使用这个框架作为最终用户验证 REST 服务,并且更容易为它们实现测试脚本.因此,我不能对 REST-assured 的 Spring MVC 部分发表太多评论.

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.

然而,这个博客 post 为您提供有关 RestAssured v2.2 的更多详细信息,其中包括构建在 MockMVC 之上的 spring-mock-mvc 模块,通过 REST 保证提供 BDD 风格流畅的界面风格.博文还警告说:

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:

何时不使用它:

RestAssuredMockMvc 不应被视为完全替代vanilla MockMvc 因为它包含与春天的MVC.例如,现在没有一流的支持诸如闪存属性和主体之类的东西.你可以如何添加那些通过使用拦截器.标准 REST Assured 还支持许多不同的身份验证方案和过滤器在 RestAssuredMockMvc API 中可用.你的另一个原因可能想要使用标准的 REST Assured API 是否重要您的组织在真实容器中测试 REST API(对于例如,如果您在容器特定方式)或者如果您使用 JAX-RS(或任何其他框架与语言无关).

RestAssuredMockMvc is not to be considered a complete replacement to vanilla MockMvc since it contains more specific features coupled to Spring MVC. For example right now there’s no first class support for things like flash attributes and principals. You can how ever add those by using an interceptor. Standard REST Assured also supports a lot of different authentication schemes and filters which are not available in the RestAssuredMockMvc API. Another reason for why you may want to use the standard REST Assured API is if it’s important to your organization to test the REST API in a real container (for example if you’ve configured authentication or authorization in a container specific manner) or if you’re using JAX-RS (or any other framework regardless of language).

最后,看看 REST-Assured spring-mvc-webapp 示例,并决定您是否愿意尝试一下并充分利用 REST-assured 和 MockMVC 框架.

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.

这篇关于RestFuse vs Rest Assured vs MockMVC Rest Service 单元测试框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆