gpt4 book ai didi

RestFuse vs Rest Assured vs MockMVC Rest 服务单元测试框架

转载 作者:行者123 更新时间:2023-12-04 03:36:44 26 4
gpt4 key购买 nike

我一直在尝试为我编写的基于 Spring MVC 的 Rest Services 找到一个简单的通用单元测试框架。

我一直在网上搜索并将其缩小到:

  • RestFuse ( http://developer.eclipsesource.com/restfuse/ )
  • 放心 ( https://github.com/jayway/rest-assured )
  • 模拟MVC(http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-mvc-controllers-rest-api/)

  • 我喜欢 RestFuse,因为它主要是基于注释的,但请放心,似乎有一种更简单的方法来传递参数和检查响应。最后作为一个 Spring MVC Rest Service 项目,我想知道我是否应该坚持使用 MockMVC 在 Spring 中测试 Rest Services 的现有方法。

    有兴趣获得任何反馈,以及性能、过去的经验以及是否还有其他我应该考虑的因素。

    最佳答案

    Rest-Assured 在 Java 中测试 REST 服务的框架已被其他框架所接受。具有 BDD 风格的流畅界面,它也易于阅读测试脚本,学习曲线最小。

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

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

    何时不使用:

    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 examples在 REST-assured 代码库中,并决定是否要尝试一下并充分利用 REST-assured 和 MockMVC 框架。

    关于RestFuse vs Rest Assured vs MockMVC Rest 服务单元测试框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34646021/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com