Java library for testing web services
I have JUnit
tests for REST web services. Now I think that JUnit
is not the best tool for that, since these tests are integration tests but not unit tests. So I probably need a Java library, which helps to send HTTP requests, verify HTTP responses, create reports and do that in parallel.
On the other hand maybe I am mistaken and Junit
(with HTTPUnit
etc.) is good enough and I don't need other tools.
What would you suggest?
I am also facing similar questions... and am starting looking around and experimenting.
I found this is other stackoverflow question: Unit testing a JAX-RS Web Service? (apparently Jersey allows to make such type of tests).
These are two options that popped up:
Keep it simple. Have a look at 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...
链接地址: http://www.djcxy.com/p/72892.html
上一篇: 什么! (双重感叹号)是什么意思?
下一篇: 用于测试Web服务的Java库