简体   繁体   English

Selenium RC的Java测试框架

[英]Java test framework for Selenium RC

I'm going to use Selenium RC to replay some tests for a website. 我将使用Selenium RC重播网站的一些测试。 I want to kickoff those tests from a Java test framework so that I get nice reports how many tests failed, etc. 我想从Java测试框架开始那些测试,以便我得到很好的报告,有多少测试失败,等等。

Which java test framework should I use? 我应该使用哪个java测试框架? Is JUnit the preferred framework for this purpose? JUnit是否是此目的的首选框架?

We use Selenium in conjunction with JUnit. 我们将Selenium与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). 这种方法的优点是易于创建JUnit测试,因为我们在Selenium IDE中记录Selenium测试,然后将它们简单地导出到JUnit(尽管通常需要进行一些小的调整)。 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. 我喜欢JUnit方法的是我团队中的每个人都已经非常熟悉JUnit,所以不需要学习曲线。

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. 我还建议您查看Selenium Grid ,它允许您并行执行测试,这样您就可以在更短的时间内完成更多工作,尤其是如果您可以在多台计算机上执行它们。

Below some of my experiences. 以下是我的一些经历。

JUnit has "rules" which allow lowering the amount of the boilerplate code. JUnit具有“规则”,允许降低样板代码的数量。 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. 例如,规则可以在测试之前启动servlet容器并在之后停止,创建并注入Selenium实例等等。 This makes tests much more elegant. 这使得测试更加优雅。

TestNG has support for groups (and their dependencies). TestNG支持组(及其依赖项)。 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. JUnit 4.8引入了可能类似的“类别”。

Spring Test has a very nice approach with "test execution listeners" which can "prepare" your test instances. Spring Test有一个非常好的方法,“测试执行监听器”可以“准备”您的测试实例。 This is somewhat similar to JUnit rules. 这有点类似于JUnit规则。 Spring Test is also test framework-agnostig, that is, your tests will almost look the same on JUnit or TestNG. Spring Test也是测试框架-agnostig,也就是说,你的测试在JUnit或TestNG上看起来几乎一样。 There's also "profiles" which are similar to TestNG groups. 还有“个人资料”与TestNG小组相似。

Here's a sample of Selenium-tested JSF application, TestNG-based. 这是一个经过Selenium测试的JSF应用程序的示例,基于TestNG。 Also take a look at my Hifaces20 Testing package, maybe you'll find some ideas useful. 另外看看我的Hifaces20测试包,也许你会发现一些有用的想法。

We have used JUnit for this purpose and it has worked quite well. 我们已经将JUnit用于此目的并且它运行良好。 The Selenium test are just treated like JUnit tests and run over the selenium server. Selenium测试只是像JUnit测试一样对待并运行在selenium服务器上。

Though Selenium test seem more closer to Integration tests and therefore you should evaluate testNG once if it suits your needs better. 虽然Selenium测试似乎更接近集成测试,因此如果它更适合您的需求,您应该对testNG进行一次评估。 TestNG gives more configuration control. TestNG提供更多配置控制。 In our case we were happy with Web driver and setup method of JUnit for us so we didn't move to TestNG. 在我们的例子中,我们对JUnit的Web驱动程序和设置方法感到满意,因此我们没有转向TestNG。

Just for supporting one of the answers 只是为了支持其中一个答案
Yahoo adapt selenium + testng for auto testing web pages. 雅虎采用selenium + testng进行自动测试网页。

Junit vs. Testng: 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. Testng可以有更多的控制,例如,分组测试用例,并行运行,重试失败的测试用例,更加灵活地注释测试用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM