用于 Web REST API 测试的 Selenium 与 XmlUnit+HttpClient

发布于 2024-10-06 16:28:17 字数 752 浏览 0 评论 0原文

我需要测试 REST 格式的 Web API 函数。目前使用 Selenium RC 对网站进行功能测试。并使用 XmlUnitHttpClient 对我们的 REST API 进行功能测试。但如果我们真的可以将功能测试代码分离到所有硒中,生活似乎会更容易。特别是使用 Selenium 2.0 的 WebDriver,使用 XPath 测试 XML 响应看起来比以往更容易。

我在 Pro XmlUnit+HttpClient 阵营中的想法:

  • 允许使用直接数据库调用轻松测试,或者 Spring beans
  • 更容易允许测试 JSON 响应,当/如果我们支持将来
  • selenium 是用于 Web UI 的,而不是REST API 测试

我在 Pro Selenium WebDriver 阵营的想法:

  • 将功能测试全部分离到标准 selenium 测试中,
  • 通过使用我们的其他 selenium UI 测试轻松测试结果,进一步测试 UI
  • 允许核心开发人员之外的其他人回顾功能 API 测试
  • 也许更容易使用像 BrowserMob 这样的服务,它使用 selenium 测试来加载测试 API?
  • 希望使用 selenium 框架进行更快的功能测试

我们使用 Spring 3 和 hibernate。什么最适合对我们的 API 进行功能测试?

I need to test web API functions in REST format. Currently using Selenium RC for functionally testing the website. And using XmlUnit and HttpClient to functionally test our REST API. But it seems life would be easier if we could really separate our functional testing code into all selenium. Particularly with Selenium 2.0's WebDriver, it looks easier than ever to test XML responses using XPath.

My thoughts in the Pro XmlUnit+HttpClient camp:

  • allows easily testing with direct database calls or Spring beans
  • more easily allows testing JSON responses when/if we support that in the future
  • selenium was meant for web UI, not REST API testing

My thoughts in the Pro Selenium WebDriver camp:

  • separates out the functional testing all into standard selenium tests
  • easily test results by using our other selenium UI tests, further testing the UI
  • allows others than core developers to review functional API tests
  • maybe easier to use services like BrowserMob, which uses selenium tests, to load test API?
  • hopefully quicker functional tests with selenium framework

We're using Spring 3 and hibernate. What's best for functionally testing our API?

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

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

发布评论

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

评论(3

筱武穆 2024-10-13 16:28:17

另一种选择可能是使用 REST Assured,这是一种用于测试 REST 服务的 Java DSL。它允许您使用很少的 XML 和 JSON 样板代码编写单元样式测试。此外,它还提供了更高级的功能,如身份验证、XSD / DTD 验证、响应代码、cookie 等。更多信息请访问他们的 使用页面

免责声明:REST Assured 是一个由我的同事发起的开源项目。

Another option might be to use REST Assured, a Java DSL for testing REST services. It allows you to write unit style tests with little boilerplate code for both XML and JSON. Additionally, it provides more advanced features like authentication, XSD / DTD validation, response codes, cookies, etc. More information is available at their usage page.

Disclaimer: REST Assured is an open source project initiated by a colleague of mine.

踏月而来 2024-10-13 16:28:17

如果您想对 Rest API 进行真正的功能测试,那么我可以推荐 Fitnesse 使用此固定装置:https://github。 com/smartrics/RestFixture

对于这种事情,Selenium 是一个糟糕的选择。

至于性能测试,您可以在几分钟内完成 Jmeter 中的其余 API 测试,无需向第三方付费。

If you want to do real functional testing on rest API's, then I can recommend Fitnesse with this fixture: https://github.com/smartrics/RestFixture

Selenium is just a poor choice for this kind of thing.

As for performance testing you can knock up rest API tests in Jmeter in a matter of minutes, no need to pay a 3rd party.

情深缘浅 2024-10-13 16:28:17

测试 API 听起来不像功能测试,而更像单元测试。所以我会选择 XmlUnit+HttpClient

Testing an API does not sound like functional testing but more like unit-testing. So I'd go for XmlUnit+HttpClient

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