开发者

How to make sure cucumber stops execution when a step fails?

Cucumber keeps executing even after a step definition has failed, and it outputs not only the failing steps, but also the passing ones. What option do I need to use in order to ensure that Cucumber stop executing as soon as it has encountered a failing step?

This is my cucumber.yml file

<%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
%>
default: <开发者_StackOverflow%= std_opts %> features
wip: --tags @wip:3 --wip features
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
autotest: <%= std_opts %> features --color


Use a cucumber hook:

After do |s| 
  # Tell Cucumber to quit after this scenario is done - if it failed.
  Cucumber.wants_to_quit = true if s.failed?
end

Or, raise an exception.

The recommended way is using a cucumber hook, though.


This lets fail fast be invoked from the command line:

# `FAST=1 cucumber` to stop on first failure
After do |scenario|
  Cucumber.wants_to_quit = ENV['FAST'] && scenario.failed?
end


As of Cucumber 2.1 you can pass the --fail-fast tag.

It should fail at the first scenario that fails and skip remaining scenarios.

Part of this PR https://github.com/cucumber/cucumber-ruby/pull/906

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜