-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
84 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,67 @@ | ||
@wip | ||
Feature: Retry failing tests | ||
|
||
Retry gives you a way to get through flaky tests that usually pass after a few runs. | ||
This gives a development team a way forward other than disabling a valuable test. | ||
|
||
- Specify max retry count in option | ||
- Output information to the screen | ||
- Output retry information in test report | ||
|
||
Questions: | ||
use a tag for flaky tests? Global option to retry any test that fails? | ||
|
||
Background: | ||
Given a scenario "Flakey" that fails once, then passes | ||
And a scenario "Shakey" that fails twice, then passes | ||
Given a scenario "Fails-once" that fails once, then passes | ||
And a scenario "Fails-twice" that fails twice, then passes | ||
And a scenario "Solid" that passes | ||
And a scenario "No Dice" that fails | ||
|
||
Scenario: | ||
When I run `cucumber -q --retry 1` | ||
And a scenario "Fails-forever" that fails | ||
|
||
Scenario: Retry once, so Fails-once starts to pass | ||
When I run `cucumber -q --retry 1 --format summary` | ||
Then it should fail with: | ||
""" | ||
7 scenarios (5 failed, 2 passed) | ||
""" | ||
And it should fail with: | ||
""" | ||
Fails-forever | ||
Fails-forever ✗ | ||
Fails-forever ✗ | ||
Solid | ||
Solid ✓ | ||
Fails-once feature | ||
Fails-once ✗ | ||
Fails-once ✓ | ||
Fails-twice feature | ||
Fails-twice ✗ | ||
Fails-twice ✗ | ||
""" | ||
|
||
Scenario: Retry twice, so Fails-twice starts to pass too | ||
When I run `cucumber -q --retry 2 --format summary` | ||
Then it should fail with: | ||
""" | ||
4 scenarios (2 passed, 2 failed) | ||
9 scenarios (6 failed, 3 passed) | ||
""" | ||
And it should fail with: | ||
""" | ||
Fails-forever | ||
Fails-forever ✗ | ||
Fails-forever ✗ | ||
Fails-forever ✗ | ||
Solid | ||
Solid ✓ | ||
Fails-once feature | ||
Fails-once ✗ | ||
Fails-once ✓ | ||
Scenario: | ||
When I run `cucumber -q --retry 2` | ||
Then it should pass with: | ||
Fails-twice feature | ||
Fails-twice ✗ | ||
Fails-twice ✗ | ||
Fails-twice ✓ | ||
""" | ||
4 scenarios (3 passed, 1 failed) | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,55 @@ | ||
# frozen_string_literal: true | ||
Given /^a scenario "([^\"]*)" that fails once, then passes$/ do |name| | ||
Given /^a scenario "([^\"]*)" that fails once, then passes$/ do |full_name| | ||
name = snake_case(full_name) | ||
write_file "features/#{name}.feature", | ||
<<-FEATURE | ||
Feature: #{name} | ||
Scenario: #{name} | ||
Feature: #{full_name} feature | ||
Scenario: #{full_name} | ||
Given it fails once, then passes | ||
FEATURE | ||
|
||
write_file "features/step_defnitions/#{name}_steps.rb", | ||
<<-STEPS | ||
Given(/^it fails once, then passes$/) do | ||
$#{name.downcase} ||= 0 | ||
$#{name.downcase} += 1 | ||
expect($#{name.downcase}).to eql 2 | ||
$#{name} += 1 | ||
expect($#{name}).to be > 1 | ||
end | ||
STEPS | ||
|
||
write_file "features/support/#{name}_init.rb", | ||
<<-INIT | ||
$#{name} = 0 | ||
INIT | ||
end | ||
|
||
Given /^a scenario "([^\"]*)" that fails twice, then passes$/ do |name| | ||
Given /^a scenario "([^\"]*)" that fails twice, then passes$/ do |full_name| | ||
name = snake_case(full_name) | ||
write_file "features/#{name}.feature", | ||
<<-FEATURE | ||
Feature: #{name} | ||
Scenario: #{name} | ||
Feature: #{full_name} feature | ||
Scenario: #{full_name} | ||
Given it fails twice, then passes | ||
FEATURE | ||
|
||
write_file "features/step_definitions/#{name}_steps.rb", | ||
<<-STEPS | ||
Given(/^it fails twice, then passes$/) do | ||
$#{name.downcase} ||= 0 | ||
$#{name.downcase} += 1 | ||
expect($#{name.downcase}).to eql 3 | ||
$#{name} ||= 0 | ||
$#{name} += 1 | ||
expect($#{name}).to be > 2 | ||
end | ||
STEPS | ||
|
||
write_file "features/support/#{name}_init.rb", | ||
<<-INIT | ||
$#{name} = 0 | ||
INIT | ||
end | ||
|
||
module SnakeCase | ||
def snake_case(name) | ||
name.downcase.gsub(/\W/, '_') | ||
end | ||
end | ||
|
||
World(SnakeCase) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters