测试 JAX-RS Web 服务? [英] Testing a JAX-RS Web Service?

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

问题描述

我目前正在寻找为 JAX-RS(Java API用于 RESTful Web 服务)基于 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 附带的示例中的单元测试.如果您对 测试用例在这里

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天全站免登陆