Question

We are using JUnit - Selenium for our web tests. We use Maven to start them and build a surefire report.

The test suite is pretty large and takes a while to run and sometimes single tests fail because the browser won't start. I want to be able run a SINGLE test using maven so I retest the tests that fail and update the report.

I can use mvn test -Dtest=TESTCLASSNAME to run all the tests in one test class, but this is not good enough since it takes about 10 minutes to run all the tests in our most complicated test classes and it's very likely that some other test will fail (because the browser wont start) and this will mess up my report.

I know I can run one test from Eclipse but that is not what I am looking for.

Any help on this would be very appriciated

Was it helpful?

Solution

c_maker's answer describes the main points - you really should consider breaking up the large test cases into multiple ones. I recommend TestNG or JUnit4 for Selenium tests so that you can easily manage the set up before the whole suite, any test dependencies, and so on. In TestNG, you can also use a group to classify tests to run selectively so that you don't need to set them to ignore when you want to run a particular class of tests.

OTHER TIPS

  1. You can have a parent class with common setup and a child class for each testcase, that way you can use mvn test -Dtest=TESTCLASSNAME to run a single test.

  2. If you are using junit4, you can annotate the methods you wish to ignore for the moment with @Ignore.

  3. If you do not have onSetup() and onTeardown() that needs to run for each testcase then you can make your test methods private and have only one testcase that call the others. This way it is easy to comment them out as needed.

If you are using the Maven Surefire Plugin, you may run this:

mvn -Dtest=TestCircle#mytest test

where TestCircle is the test class, and mytest is the test method name.

Not directly related, but if you are using Cucumber to run scenarios, you may run a single scenario in a single feature file by doing this:

mvn -P selenium,chrome -Dcucumber.options="classpath:com/my/package/myfeature.feature:47" clean verify

where line 47 is the start of the scenario you wish to run, and "chrome" is your test browser profile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top