Rerun failed scenarios using Cucumber?

1 min


639
1 share, 639 points
rerun failed scenarios using cucumber
rerun failed scenarios using cucumber

How to rerun failed scenarios using Cucumber

Having your tests failed because of unreliable environment is a very common issue within the projects,I will try to cover in this article how to rerun failed scenarios using Cucumber.

So let’s not forget tests are created to fail, right ? That’s why we write tests against functionality to make then fail but having failed tests when there is no functionality broken is frustrating.

So imagine a simple scenario :

@foo
Feature: Basic Arithmetic

  Scenario: Adding
  # Try to change one of the values below to provoke a failure
    When I add 4 and 5
    Then the result is 9

When we execute the tests we need to use the rerun Cucumber formatter:

cucumber -t @foo -f rerun --out rerun.txt || cucumber @rerun.txt

So this guy will run your @foo tag and if there will be any failures will throw the test into rerun.txt file and rerun once the execution will finish from cucumber -t @foo.

If you are running your tests using docker containers in parallel you can still do it and works like a charm :

./bin/run_tests.sh ${container_name} docker.host/docker-image:${env.BUILD_NUMBER} -p ${profile} -f rerun --out rerun.txt || cucumber @rerun.txt TEST_ENV='test';

There are other ways to do it using Rake as well but for me this works and is quite simple and I could not find any problem with it.

Using Jenkins you don’t even need to care about the reports if are merged or not , Jenkins will do that for you.

My suggestion is not to rely only on the rerun to fix the issue , because is not fixing the cause . In my project I throw all the exceptions even if for the second time is passing the tests and I start further investigations to see why the tests failed first.

Happy Testing!


Like it? Share with your friends!

639
1 share, 639 points

What's Your Reaction?

cute cute
0
cute
scary scary
1
scary
wtf wtf
0
wtf
geek geek
0
geek
WIN WIN
1
WIN
Love Love
0
Love
OMG OMG
0
OMG
Angry Angry
0
Angry
Lol Lol
1
Lol
Test engineer

0 Comments

Your email address will not be published. Required fields are marked *

Choose A Format
Trivia quiz
Story