简体   繁体   中英

How to rerun failed test cases in cucumber-jvm?

I am using cucumber-jvm + Junit + Maven to run my test cases . I could not able to find any methods to rerun my failed test cases . I have checked this Rerunning failed cucumber tests using cucumber-jvm . But the workaround does not working fine .

It would be good if you have any other way to rerun the test cases.

See the answer starting with "You can pass cucumber options to mvn as below" in Rerunning failed cucumber tests using cucumber-jvm

The following is copied from the above link based on asker's request

You can pass cucumber options to mvn as below

 mvn clean verify  -Dcucumber.options="@rerun.txt"

Note there is a tricky part here. If you are using the same test runner for both first run and rerun (and I believe that's what you want), then the test runner would contains something like

@CucumberOptions(plugin = { "rerun:target/rerun.txt"})

If you fire your rerun with maven using the same rerun file name as below

 mvn clean verify  -Dcucumber.options="@target/rerun.txt"

then cucumber will complain it could not find the rerun file. Why? Because the plugin "rerun:target/rerun.txt" will delete the file first with this test runner.

Workaround is copy/rename the file first, then kick off the mvn run like

mv target/rerun.txt rerun.txt &&  mvn clean verify  -Dcucumber.options="@rerun.txt"

And this is actually what you want. Because say if there are 5 failed scenarios in file target/rerun.txt. And with the rerun after some fix, 2 of them passed. Now the target/rerun.txt will contain the remaining 3 failed scenarios only, which would be your new start point along the debugging way.

Use the rerun plugin to generate a list of scenarios that failed:

java cucumber.api.cli.Main --plugin rerun:rerun.txt features

This will write the location of each failing scenario to a text file called rerun.txt (you can call it whatever you want). Then you can use the output file as an input to your next run of Cucumber to specify which scenarios should be executed:

java cucumber.api.cli.Main < rerun.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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