views:

546

answers:

5

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?

+1  A: 

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.

Fazal
I'm heading for a functional test, so checking if the most important features of the website are still working. Indeed, JUnit is most often used for class tests only so I'm not sure if I should go for JUnit.
Sebi
+3  A: 

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.

Chris Knight
Thanks for sharing your experience. I think being able to directly export from Selenium IDE to JUnit tests is a great plus. But let's see what other people think.
Sebi
+2  A: 

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.

lexicore
A: 

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.

Jim Horng
I ended up using JUnit. The reason is simple: I started setting up the whole thing with JUnit and now I run out of time to also try testng :-(
Sebi
JUnit is great anyway. have fun.
Jim Horng
A: 

hi

Do we have someother selenium frameworks other than junit and testingNG with java

shabina