Selenium RC 的 Java 测试框架
我将使用 Selenium RC 重播网站的一些测试。我想从 Java 测试框架启动这些测试,以便获得良好的报告,有多少测试失败了,等等。
我应该使用哪个 Java 测试框架? JUnit 是用于此目的的首选框架吗?
I'm going to use Selenium RC to replay some tests for a website. I want to kickoff those tests from a Java test framework so that I get nice reports how many tests failed, etc.
Which java test framework should I use? Is JUnit the preferred framework for this purpose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我们将 Selenium 与 JUnit 结合使用。这种方法的优点在于可以轻松创建 JUnit 测试,因为我们在 Selenium IDE 然后简单地将它们导出到 JUnit(尽管通常需要进行一些小的调整)。然后,您可以相当轻松地将它们集成到持续集成构建中,并设置一个作业以每小时或任何适合的方式运行它们。我喜欢 JUnit 方法的一点是,我团队中的每个人都已经非常熟悉 JUnit,因此不需要学习曲线。
我还建议您查看 Selenium Grid 它允许您并行执行测试,从而获得在更短的时间内完成更多的工作,特别是如果您可以利用在多台机器上执行它们的优势。
We use Selenium in conjunction with JUnit. The beauty of this method is the ease of creation of the JUnit tests since we record the Selenium tests in the Selenium IDE and then simply export them to JUnit (though some small tweaking is often necessary). You can then fairly easily integrate them into your continuous integration build and set a job to run them every hour or whatever suits. What I like about the JUnit approach is that everyone on my team is already intimately familiar with JUnit, so no learning curve required.
I'd also recommend checking out Selenium Grid which allows you to execute your tests in parallel allowing you to get through a lot more in a shorter time especially if you can take advantage of executing them across multiple machines.
下面是我的一些经历。
JUnit 有“规则”,可以减少样板代码的数量。例如,规则可以在测试之前启动 servlet 容器并在测试之后停止,创建并注入 Selenium 实例等。这使得测试更加优雅。
TestNG 支持组(及其依赖项)。这对于集成测试非常有用 - 例如,您可以在某些环境中关闭某些组。 JUnit 4.8 引入了可能类似的“类别”。
Spring 测试 有一个非常好的“测试执行监听器”方法,可以“准备”您的测试实例。这有点类似于 JUnit 规则。 Spring Test 也是与测试框架无关的,也就是说,您的测试在 JUnit 或 TestNG 上看起来几乎相同。还有类似于 TestNG 组的“配置文件”。
这里是一个经过 Selenium 测试的 JSF 应用程序示例,基于 TestNG。另请看看我的 Hifaces20测试包,也许你会发现一些有用的想法。
Below some of my experiences.
JUnit has "rules" which allow lowering the amount of the boilerplate code. For instance, a rule can start a servlet container before the test and stop it after, create and inject a Selenium instance and so on. This makes tests much more elegant.
TestNG has support for groups (and their dependencies). This is extremely useful for integration testing - for instance you can turn of certain groups in certain environments. JUnit 4.8 introduces "categories" which may be something similar.
Spring Test has a very nice approach with "test execution listeners" which can "prepare" your test instances. This is somewhat similar to JUnit rules. Spring Test is also test framework-agnostig, that is, your tests will almost look the same on JUnit or TestNG. There's also "profiles" which are similar to TestNG groups.
Here's a sample of Selenium-tested JSF application, TestNG-based. Also take a look at my Hifaces20 Testing package, maybe you'll find some ideas useful.
我们为此目的使用了 JUnit,并且效果非常好。 Selenium 测试就像 JUnit 测试一样,并在 selenium 服务器上运行。
尽管 Selenium 测试看起来更接近集成测试,因此如果 testNG 更适合您的需求,您应该评估一次。 TestNG 提供更多配置控制。在我们的案例中,我们对 JUnit 的 Web 驱动程序和设置方法感到满意,因此我们没有转向 TestNG。
We have used JUnit for this purpose and it has worked quite well. The Selenium test are just treated like JUnit tests and run over the selenium server.
Though Selenium test seem more closer to Integration tests and therefore you should evaluate testNG once if it suits your needs better. TestNG gives more configuration control. In our case we were happy with Web driver and setup method of JUnit for us so we didn't move to TestNG.
只是为了支持其中一个答案
雅虎采用
selenium + testng
来自动测试网页。Junit 与 Testng:
Testng 可以有更多的控制,例如对测试用例进行分组、并行运行、重试失败的测试用例、更灵活地注释测试用例。
http://www.mkyong.com/unittest/junit-4 -vs-testng-比较/
“http://www.ibm.com/developerworks/java/library/ j-cq08296/"
Just for supporting one of the answers
Yahoo adapt
selenium + testng
for auto testing web pages.Junit vs. Testng:
Testng can have more control such as, grouping test cases, run in parallel, re-try failed test case, more flexible on annotating test case.
http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/
"http://www.ibm.com/developerworks/java/library/j-cq08296/"