开发者

Maven - Selenium - Possible to run only one test

开发者 https://www.devze.com 2022-12-23 13:52 出处:网络
We are using JUnit - Selenium for our web tests. We use Maven to start them and b开发者_JAVA技巧uild a surefire report.

We are using JUnit - Selenium for our web tests. We use Maven to start them and b开发者_JAVA技巧uild 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


  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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号