单元测试JAX-RS Web服务? [英] Unit testing a JAX-RS Web Service?

查看:138
本文介绍了单元测试JAX-RS Web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找为 JAX-RS (Java API)创建自动化测试的方法基于RESTful Web Services的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.

您使用什么方法来测试您的网络服务?

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附带的示例中的单元测试。如果您对 Apache Camel 中测试REST支持。 http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-rest/src/test/java/org/apache/camel/rest/resources/\"rel =noreferrer>测试用例在这里

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

这篇关于单元测试JAX-RS Web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆