适合 http 的 java 单元测试库是什么?
我正在开发一个 servlet 应用程序,我使用 JWebUnit 来检查所有基本响应,但现在我必须开始使用与 GET(POST、PUT 和 DELETE)不同的其他 HTTP 方法。
所以,我找到了 HttpUnit,它看起来支持我需要的东西,那里有 POST 和 PUT 方法,我想我可以通过 HttpUnit 支持的 HEAD 来绕过 DELETE 方法。
然而我发现这个项目最近没有任何活动;上次发布是大约两年前。所以我的问题是人们是否使用其他库或者 HttpUnit 适合我的情况?
谢谢。
I am developing a servlet application, I was using JWebUnit, to check all the basic responses, but now I have to start using other HTTP methods different to GET(POST,PUT and DELETE).
So, I found HttpUnit, it looks that have support for what I need, POST and PUT methods are available there and I guess I can walk around the DELETE method through the HEAD which is supported by HttpUnit.
However I found there is no recent activity in this project; the last release was about two years ago. so my question is if there is any other library that people is using for it or HttpUnit is the right for my case?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Httpunit 是一个成熟的库。它非常适合您想要做的事情。
Httpunit is a mature library. It works just fine for what you are trying to do.
我推荐使用 HtmlUnit。无意对 HttpUnit 表示不尊重:几年前我使用过它,而且效果很好。然而,它作为一个项目已经消亡了很多年,更具体地说,它对 Javascript 的支持很少,所以我转而使用 HtmlUnit
HtmlUnit 自诞生以来一直在稳步发展,并且具有出色的 Javascript 支持。我用它来测试包含大量 Ajax 的站点,我认为只有一次它没有正确执行 JS 代码(结果是一个很小的 HtmlUnit bug,我修复了)。有很多钩子可以帮助您测试正在发生的事情。
另外,正如该网站所说,“HtmlUnit 被 Canoo WebTest、JWebUnit、WebDriver、JSFUnit、Celerity 等不同的开源工具用作底层‘浏览器’”,我没有使用过这些工具,因为我更喜欢表达我用 Java 进行测试,但我知道 HtmlUnit 非常适合它们。
I recommend HtmlUnit instead. No disrespect intended towards HttpUnit: I used it a few years ago and it worked well. However it died as a project for a number of years, and more particularly it had little support for Javascript, so I switched to HtmlUnit
HtmlUnit has been steadily developed since its inception and has exceptional Javascript support. I have used it to test sites containing a lot of Ajax and only once, I think, did it not properly execute the JS code (turned out to be a wee HtmlUnit bug, which I fixed). There are a lot of hooks available to help you test what's going on.
As well, as the site says, "HtmlUnit is used as the underlying 'browser' by different Open Source tools like Canoo WebTest, JWebUnit, WebDriver, JSFUnit, Celerity, ..." I haven't used those, as I prefer expressing my tests in Java, but I understand HtmlUnit works well for them.
同意@Sasi。
还应该注意的是,偶尔会签入项目的 SVN 存储库。最近一次是几个月前,为一个错误应用了贡献的补丁。所以仍然有开发人员负责代码。
Agreed with @Sasi.
It should also be noted that there are occasional checkins to the project's SVN repository. The most recent were a couple of months ago to apply a contributed patch for a bug. So there are still developers taking care of the code.
您可以尝试REST Assured,这会让事情变得非常简单在 Java 中发出 http 请求并验证响应。
You can try out REST Assured which makes it very simple to make http requests and validate the response in Java.