【问题标题】:Java library for testing web services用于测试 Web 服务的 Java 库
【发布时间】:2013-07-11 20:14:45
【问题描述】:

我有 REST Web 服务的 JUnit 测试。现在我认为JUnit 不是最好的工具,因为这些测试是integration 测试而不是unit 测试。所以我可能需要一个 Java 库,它可以帮助发送 HTTP 请求、验证 HTTP 响应、创建报告并并行执行这些操作。

另一方面,也许我弄错了,Junit(与HTTPUnit 等)已经足够好了,我不需要其他工具。

你有什么建议?

【问题讨论】:

    标签: java web-services junit integration-testing


    【解决方案1】:

    我也面临着类似的问题......并开始四处寻找和尝试。

    我发现这是另一个 stackoverflow 问题:Unit testing a JAX-RS Web Service?(显然 Jersey 允许进行此类测试)。

    这是弹出的两个选项:

    【讨论】:

      【解决方案2】:

      保持简单。看看https://github.com/valid4j/http-matchers

      // Statically import the library entry point:
      import static org.valid4j.matchers.http.HttpResponseMatchers.*;
      
      // Invoke your web service using plain JAX-RS. E.g:
      Client client = ClientBuilder.newClient();
      Response response = client.target("http://example.org/hello").request("text/plain").get();
      
      // Verify the response
      assertThat(response, hasStatus(Status.OK));
      assertThat(response, hasHeader("Content-Encoding", equalTo("gzip")));
      assertThat(response, hasEntity(equalTo("content")));
      // etc...
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-11-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多