JUnit - 测试网站

发布于 2024-09-16 02:09:48 字数 275 浏览 8 评论 0原文

我对 JUnit 很陌生,但我想设置一些执行以下操作的测试。

  1. 测试一系列服务器到服务器 API 调用 - 验证响应是否正确 - 我可以做到这一点。

  2. 打开一个网页,在其中输入数据并验证提交时发生的情况 - 这是我正在努力解决的问题。这可能吗?

我想我可以使用服务器端 http Web 请求来调用网页,但我不确定如何与网站本身交互,即在表单中输入数据。

有什么想法吗?

谢谢

史蒂夫

I'm very new to JUnit, but I want to set up some tests which does the following..

  1. Tests a range of server to server API calls - verifying the responses are correct - I can do that fine.

  2. Open a web page, enter data onto it and verify what happens on submit - This I am struggling with. Is it even possible?

I am thinking that I could call a web page using a server side http web request, but I'm not sure how I can interact with the site itself, i.e. enter data into the forms.

Any thoughts?

Thanks

Steve

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

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

发布评论

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

评论(4

蒗幽 2024-09-23 02:09:48

您可以使用 Selenium 来实现此目的。我建议您使用当前正在开发的版本 2,应该很快就会推出测试版(alpha 版本已经可用)。

You could use Selenium for this. I suggest you use the version 2 which is currently in development and should have a beta available soon (alphas are already available).

嘦怹 2024-09-23 02:09:48

看看 Selenium,它是一个测试 Web 应用程序(以及事实上的网站)的系统,您可以编写所有测试在Java中。有一个名为 Tellurium 的项目,基于 Selenium,但 Tellurium 可以与 groovy 和 DSL 配合使用,一开始可能会更容易处理。

这是如何工作的?

  • 首先,您在 java (Selenium) 或 groovy (Tellurium) 中创建测试
  • ,然后开始测试。它将与您的网络浏览器配合使用。该应用程序将与您的浏览器交互,以测试应用程序的每一寸(如您编码的那样)。
  • 最后,它会为您提供有关测试的报告,就像 JUnit 一样。

Have a look at Selenium, it's a system to test web applications (and de facto websites) you can write all your tests in java. There is an ather project named Tellurium, based on Selenium but Tellurium works with groovy and a DSL, it might be easier to handle at first.

How does this works ?

  • First you create tests in java (Selenium) or groovy (Tellurium)
  • Then you start your tests. It will work with your web browser. The application will interact with your browser to test every inch of your application (as you coded it)
  • At the end it give you a report about yours tests, just as JUnit do.
晒暮凉 2024-09-23 02:09:48

您还可以利用网络的性质。没有真正的理由渲染表单、填写并提交它来测试表单处理代码。表单的显示是一个HTTP请求,提交是另一个。通过模拟浏览器将发送的内容并断言其处理正确来测试表单提交代码是完全合理的。

您确实需要确保表单呈现和提交测试代码同步,但您也不一定需要对此进行完全集成。

有些工具允许在不启动浏览器的情况下进行测试...我想到的一个是 HTMLUnit (和还有其他的)。如果您发现 Selenium 编写起来很痛苦,或者测试很脆弱或不稳定,请寻找像这样的更简单的工具。

You can also exploit the nature of the web. There's no real reason to render a form, fill it out and submit it to test the form processing code. The display of the form is one HTTP request, and the submission is another. It's perfectly reasonable to test form submission code by mocking up what a browser would send and asserting that it's handled correctly.

You do need to make sure that the form rendering and submission test code are in sync, but you don't necessarily need a full integration for this either.

There are tools that allow testing without booting up a browser... one that springs to mind is HTMLUnit (and there are others). If you find that Selenium is a pain to write, or the tests brittle or flakey, look for simpler tools like this.

昵称有卵用 2024-09-23 02:09:48

我建议您尝试机器人框架。这是由诺基亚西门子通信工程师开发的开源测试框架。

它主要基于 python 和 Selenium 测试库构建。它还支持通过 Jython 库测试 Java/J2EE 服务器端代码。我个人有时会在工作中使用它,编写测试用例就像通过使用关键字描述端到端流程一样简单(大多数必需的关键字已经内置)。如果您发现 Selenium 很难使用,您可以尝试一下。 Robot 框架提供了对原始 selenium 的相当简单的抽象,并且还具有进行 Java/J2EE 服务器端调用的功能。

问候,
纳根德拉大学

I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.

It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.

Regards,
Nagendra U M

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