【问题标题】:How to make sure cucumber stops execution when a step fails?当步骤失败时如何确保黄瓜停止执行?
【发布时间】:2016-07-01 02:47:18
【问题描述】:

即使在步骤定义失败后,Cucumber 也会继续执行,它不仅输出失败的步骤,还输出通过的步骤。我需要使用什么选项来确保 Cucumber 在遇到失败步骤后立即停止执行?

这是我的 cucumber.yml 文件

<%
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: <%= 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

【问题讨论】:

    标签: ruby-on-rails cucumber


    【解决方案1】:

    使用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
    

    或者,引发异常。

    不过,推荐的方法是使用黄瓜钩。

    【讨论】:

      【解决方案2】:

      这样可以从命令行快速调用失败:

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

      【讨论】:

        【解决方案3】:

        从 Cucumber 2.1 开始,您可以传递 --fail-fast 标签。

        它应该在第一个失败的场景中失败并跳过剩余的场景。

        此 PR 的一部分https://github.com/cucumber/cucumber-ruby/pull/906

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-06-05
          • 1970-01-01
          • 2018-02-08
          • 1970-01-01
          相关资源
          最近更新 更多