2013-07-13 86 views
7

我有JUnit测试REST Web服务。现在我认为JUnit不是最好的工具,因为这些测试是集成测试但不是单元测试。所以我可能需要一个Java库,它有助于发送HTTP请求,验证HTTP响应,创建报告并且并行执行。用于测试Web服务的Java库

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

你会建议什么?

回答

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...