如何将 Cucumber 测试结果保存到文件中

How to save Cucumber test results to a file

我有一些 Cucumber 测试可以从控制台 运行

rake cucumber

是否有将测试结果存储到文本文件的命令行选项?

或者

  • 运行 cucumber直接使用-o。来自 cucumber --help:

    -o, --out [FILE|DIR]
        Write output to a file/directory instead of STDOUT. This option
        applies to the previously specified --format, or the
        default format if no format is specified. Check the specific
        formatter's docs to see whether to pass a file or a dir.
    
  • 运行rakeCUCUMBER_OPTS="-o whateverfile",即

    CUCUMBER_OPTS="-o whateverfile" rake cucumber # assuming you're using a Bourne family shell
    

    rake CUCUMBER_OPTS="-o whateverfile" cucumber
    
  • 编辑 lib/tasks/cucumber.rake 并添加

    t.cucumber_ops = '-o whateverfile'
    

    Cucumber::Rake::Task中的一个或多个

  • 或者自己重定向cucumber命令的输出:

    cucumber > whateverfile
    

-o 与重定向略有不同:它总是将 "progress" 输出打印到屏幕上。如果您不指定格式,它会将默认的 "pretty" 格式放入文件中。如果您这样做(例如 cucumber -f html -o whateverfile),它会将您指定的格式放入文件中。

以防万一,我正在使用 Ruby Cucumber 2.3.2。