是否有用于测试 RESTful API 的 Java 包?

发布于 2024-08-29 02:51:39 字数 398 浏览 3 评论 0原文

我正准备深入测试 RESTful 服务。我们的大部分系统都是用 Java 和 Eclipse 构建的,所以我希望继续留在那里。

我已经找到了rest-client (http://code.google.com/p/rest -client/)用于进行手动和探索性测试,但是是否有一堆 java 类可以让我的生活更轻松?我使用 testNG 作为测试平台,但希望能够节省我时间的帮助程序库。

我找到了 http4e (http://www.ywebb.com/),但我真的很想要一些东西自由和开放源码软件。

I'm getting ready to dive into testing of a RESTful service. The majority of our systems are built in Java and Eclipse, so I'm hoping to stay there.

I've already found rest-client (http://code.google.com/p/rest-client/) for doing manual and exploratory testing, but is there a stack of java classes that may make my life easier? I'm using testNG for the test platform, but would love helper libraries that can save me time.

I've found http4e (http://www.ywebb.com/) but I'd really like something FOSS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

眼趣 2024-09-05 02:51:39

您可以使用 REST Assured,这使得从 JUnit 或 TestNG 测试和验证 Java 中的 REST 服务变得非常容易。例如,假设对名为“/lotto”的服务的 GET 请求返回以下 JSON

{
“乐透”:{
“乐透ID”:5,
"中奖号码":[2,45,34,23,7,5,3],
“获胜者”:[{
“获胜者ID”:23,
“数字”:[2,45,34,23,3,5]
},{
“获胜者ID”:54,
“数字”:[52,3,12,11,18,22]
}]
}
然后

您可以使用 REST Assured 发出请求并验证响应(在本例中,lotto id 等于 5),如下所示:

expect().body("lotto.lottoId", equalTo(5)).when().get("/lotto");

You can use REST Assured which makes it very easy to test and validate REST services in Java from JUnit or TestNG. E.g. let's say that a GET request to a service called "/lotto" returns the following JSON

{
"lotto":{
"lottoId":5,
"winning-numbers":[2,45,34,23,7,5,3],
"winners":[{
"winnerId":23,
"numbers":[2,45,34,23,3,5]
},{
"winnerId":54,
"numbers":[52,3,12,11,18,22]
}]
}
}

then you can make the request and validate the response (in this case that lotto id equal to 5) with REST Assured like this:

expect().body("lotto.lottoId", equalTo(5)).when().get("/lotto");
嘿哥们儿 2024-09-05 02:51:39

JMeter 是一个选择吗?它具有 HTTP 请求采样器,支持所有 HTTP 方法和断言以验证响应。

另一种选择可能是像soapUI这样的东西,它有一个API,可以与您的测试集成案例,虽然我还没有尝试过。

Would JMeter be an option? It has HTTP Request samplers that support all of the HTTP methods and assertions to validate the response.

Another alternative might be something like soapUI which has an API that could be integrated with your test cases, though I haven't tried it.

小帐篷 2024-09-05 02:51:39

CXF 显然支持 休息。我自己还没有尝试过 REST 支持,但我认为 CXF 是一个出色的、灵活的、基于标准的 Web 服务实现。

CXF apparently has support for REST. I haven't tried the REST support yet myself, but I think CXF is a superb, flexible, standards-based webservice implementation.

硬不硬你别怂 2024-09-05 02:51:39

Another informal option to test your REST services is by using the Firefox RESTClient Add-on.
Postman REST Client for Google Chrome is another option.

黑凤梨 2024-09-05 02:51:39

显然 rest-client 内置了一个库。我将其与 testNG 一起使用和 XStream,它似乎正是医生所要求的。

Apparently rest-client has a library built in. I'm using that with testNG and XStream and it seems to be exactly what the doctor ordered.

述情 2024-09-05 02:51:39

我今天正在围绕休息服务进行单元测试,我需要测试已部署的服务器以检查一些并发要求,因此我需要测试部署的休息服务。

起初,我尝试了 Johan 建议的解决方案,并从 REST Assured 开始,取得了一些成功,但寻找更多文档,我发现了这个:

http://uttesh.blogspot.com/2012/09/spring-rest-web-service-test.html

它基于 spring库,所以如果你使用 spring,你将继续使用来自同一供应商的东西,这总是好的。

我还发现 spring 的库比 REST Assured 更容易理解,但这只是我的问题;)

I was working today around the unit testing of a rest service, I needed to test the deployed server in order to check some concurrency requeriments, so I needed to test the deployes rest service.

At first I tried the solution sugested by Johan, and started with REST Assured with some succes, but look for more documentation, I found this:

http://uttesh.blogspot.com/2012/09/spring-rest-web-service-test.html

its based on a spring library, so if you are using spring, you'll keep using the stuff from the same vendor, which is always nice.

Also I found the libs from spring easier to understand than REST Assured, but it's just me ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文