【发布时间】:2015-11-05 16:34:03
【问题描述】:
一些设置:我们是使用 Jruby/Cucumber 为我们的 ETL 流程编写验收测试的数据仓库生产线。这一端到端流程涉及连续启动约 15 个 Informatica 工作流。我提到这一点只是为了让熟悉 Informatica 的人理解为什么我说运行单个 Cucumber 场景需要大约 3 分钟。将其中的 20 个放入一个功能中,现在运行时长为一个小时。
我们使用 Jenkins 作为 CI 服务器每晚运行我们的黄瓜测试。目前,如果我们有一个场景失败,我们会进入并修复有问题的代码,然后必须重新启动整个工作,等待长达一个小时的反馈。我们正在寻找的是一种使用可选参数在 jenkins 中启动工作的方法,该参数只会重新运行上一次运行失败的场景,从而让我们更快地从红到绿。
查看有关重新运行失败场景的其他一些问题,我能够提出以下 Rake 任务:
Cucumber::Rake::Task.new(:task_name) do |t|
rerun_file = "temp/task_name_rerun.txt"
tags = "--tags ~@wip --tags @task_name"
html_output = "--format html --out features/build_results/task_name.html"
junit_output = '--format junit --out features/build_results/reports'
rerun_output = "--format rerun --out #{rerun_file}"
outputs = [html_output, junit_output, rerun_output]
if (ENV['Rerun'] == 'TRUE')
t.cucumber_opts = "@#{rerun_file} #{html_output}"
else
t.cucumber_opts = "--format pretty #{tags} #{outputs.join(' ')}"
end
end
当我第一次使用 Rerun = FALSE 运行时,它运行良好,并且完全按照预期创建了 task_name_rerun.txt 文件。但是,当我打开重新运行并再次启动它时,它就像我没有传递任何场景一样,给出以下输出:
C:\jruby-1.7.20\bin\jruby.exe --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\jruby-1.7.20\bin/rake task_name
io/console not supported; tty will not be manipulated
C:/jruby-1.7.20/bin/jruby -S bundle exec cucumber @temp/task_name_rerun.txt --format html --out features/build_results/task_name.html
io/console not supported; tty will not be manipulated
io/console not supported; tty will not be manipulated
Process finished with exit code 0
当我将选项更改为简单时
t.cucumber_opts = "@#{rerun_file}"
确实找到了场景,但现在找不到相关的步骤:
C:\jruby-1.7.20\bin\jruby.exe --1.9 -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) C:\jruby-1.7.20\bin/rake task_name
io/console not supported; tty will not be manipulated
C:/jruby-1.7.20/bin/jruby -S bundle exec cucumber @temp/task_name_rerun.txt
io/console not supported; tty will not be manipulated
io/console not supported; tty will not be manipulated
@task_name
Feature: My Feature
Scenario: One should Equal One # features/scenarios/extended/path/my_test.feature:4
Given I have a passing test # features/scenarios/extended/path/my_test.feature:5
1 scenario (1 undefined)
1 step (1 undefined)
0m0.180s
You can implement step definitions for undefined steps with these snippets:
Given(/^I have a passing test$/) do
pending # Write code here that turns the phrase above into concrete actions
end
Process finished with exit code 0
所以,我的问题有点双重:
1) 是否可以将 cucumber 与重新运行文件一起使用并应用其他格式?我发现的所有其他相关问题都涉及立即重新运行 Rake 任务,因此失败场景的构建报告仍会发布给 Jenkins。但是,由于我想再次启动它,只执行一次重新运行,如果 Jenkins 找不到最近的 html 报告,即使所有场景都变绿了,if 也会将该作业标记为不稳定。理想情况下,我还想再次输出重新运行的失败,这样如果最初有 10 个场景失败,我们修复其中的 5 个并重新运行,那么 rerun.txt 文件将只包含最近的 5 个失败。
2) 我不确定为什么重新运行突然找不到我的步骤定义。我目前的猜测是因为我的功能文件没有直接在 features/scenarios/.在基于标签运行之前,这从来没有给我们带来过问题,所以我不明白为什么用场景行号调用特定功能会突然破坏它。但是,我尚未验证移动文件是否有效。
编辑:我解决了第二个问题。上面我使用了一堆虚拟文件/文件夹名称来发布问题,在我们的实际测试套件中,嵌套文件夹名称中有空格。一旦我删除了 Spaces,它就可以正常运行测试了。
一些可能有帮助的额外细节:
- Jruby 版本:1.7.20
- 黄瓜版本:2.0.0
- 运行于:Windows 7
【问题讨论】:
-
是否可以在命令行环境中运行各个场景?可以放入Windows批处理文件的东西?如果是,那么您可以解析结果文件并提取失败的场景名称。然后,您可以将这些参数传递给将运行这些场景的批处理文件。 Jenkins 可以轻松运行 Windows 批处理文件并使用传递给它的参数。抱歉,对 Ruby 或 Rake 不太了解,无法从该方向给出任何指示。
标签: jenkins cucumber rake jruby