测试JAX-RS Web服务?

测试JAX-RS Web服务?

问题描述:

我目前正在寻找为 JAX-RS (Java API)创建自动测试的方法用于基于REST的Web服务).

I'm currently looking for ways to create automated tests for a JAX-RS (Java API for RESTful Web Services) based web service.

我基本上需要一种发送某些输入并验证我是否获得了预期响应的方法.我更愿意通过JUnit做到这一点,但我不确定如何实现.

I basically need a way to send it certain inputs and verify that I get the expected responses. I'd prefer to do this via JUnit, but I'm not sure how that can be achieved.

您使用哪种方法来测试您的Web服务?

What approach do you use to test your web-services?

更新:正如entzik所指出的那样,将Web服务与业务逻辑分离可以让我对业务逻辑进行单元测试.但是,我也想测试正确的HTTP状态代码等.

Update: As entzik pointed out, decoupling the web service from the business logic allows me to unit test the business logic. However, I also want to test for the correct HTTP status codes etc.

Jersey 带有一个出色的RESTful客户端使编写单元测试非常容易的API.请参阅Jersey附带的示例中的单元测试.如果您对测试案例在这里

Jersey comes with a great RESTful client API that makes writing unit tests really easy. See the unit tests in the examples that ship with Jersey. We use this approach to test the REST support in Apache Camel, if you are interested the test cases are here