我为REST web服务编写了JUnit测试。现在我认为JUnit不是最好的工具,因为这些测试是集成测试而不是单元测试。所以我可能需要一个Java库,它可以帮助发送HTTP请求,验证HTTP响应,创建报告并并行执行。
另一方面,也许我错了,JUnit(与HTTPUnit等)已经足够好了,我不需要其他工具。
你会建议什么?
另一方面,也许我错了,JUnit(与HTTPUnit等)已经足够好了,我不需要其他工具。
你会建议什么?
// 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...
我也面临类似的问题......并开始四处寻找和尝试。
我在其他StackOverflow问题中发现了这个链接:Unit testing a JAX-RS Web Service?(显然,Jersey允许进行这种类型的测试)。
这里有两个选项: