2013-07-13 118 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...