简体   繁体   English

首次失败时退出Minitest吗?

[英]Minitest Exit on first failure?

I'm using Minitest with Rails. 我正在使用Minitest和Rails。

How do I get it to exit on the first failure if I'm running a bunch of tests? 如果运行大量测试,如何在第一次失败时退出? I want this to happen when I'm writing the tests because it's a waste of time for later tests to run after the failed one. 我希望在编写测试时会发生这种情况,因为在失败的测试之后再进行测试是浪费时间的。

You can probably use the minitest-fail-fast gem. 您可能可以使用minitest-fail-fast gem。 You may also modify the Minitest reporters engine to exit after reporting a failure. 您也可以将Minitest报告程序引擎修改为报告失败后exit

I've just found this answer while searching for the solution, but at least in Rails 5.1 you have one option: 我只是在搜索解决方案时找到了这个答案,但是至少在Rails 5.1中,您有一个选择:

rails test -h Usage: bin/rails test [options] [files or directories]

You can run a single test by appending a line number to a filename:

    bin/rails test test/models/user_test.rb:27

You can run multiple files and directories at the same time:

    bin/rails test test/controllers test/integration/login_test.rb

By default test failures and errors are reported inline during a run.

Rails options:
    -w, --warnings                   Run with Ruby warnings enabled
    -e, --environment                Run tests in the ENV environment
    -b, --backtrace                  Show the complete backtrace
    -d, --defer-output               Output test failures and errors after the test run
    -f, --fail-fast                  Abort test run on first failure or error
    -c, --[no-]color                 Enable color in the output

So you just just need to run rails test -f 所以你只需要运行rails test -f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM