How to make a mini-stop stop on failure?

I use Minitest as a runner for my functional tests, using Selenium as a driver to launch the browser. Each test is modeled as MiniTest :: Unit :: TestCase.

Minitest reports the execution results when it completes all tests. Exceptions that have been detected are also printed at the end of the run. It's hard for me to debug when something unexpected fails because the execution context is lost. The exceptions that I execute are not deterministic.

Is there a way to force the Minitest runner to stop running tests when an exception or statement fails?

I am using minitest (2.11.2) and ruby โ€‹โ€‹1.9.2p290 (2011-07-09) [i386-mingw32]

+8
source share
5 answers

I think you want to have the option "fast fail". I found fail_fast for minitest (Test :: Unit): immediate traceback and exit , but this is deprecated (still covering what can be done). I think you will need to secure your test library to enable this option. I found a Gist showing how to add a simple option with a quick check on minitest/turn/minitest-rails so that you can be on the right track. I understand that your problem is related to the first article I referred to:

When I run the Test :: Unit set in my Ruby on Rails 3 project through rake test and the test does not work, the default behavior is just to type โ€œFโ€ or โ€œEโ€, continue to work until all tests are complete (until I I roll my thumbs), and only then print a stack trace.

+3
source

As I answered here , I found a gem for: minitest-fail-fast . It works with Rails 4.2 and Minitest 5.6.1

+2
source

try rails test -f will do this. This means aborting the test run of the first failure or error.

+2
source

It does not give a direct answer to the question, but can be very useful.

You can use the pry-rescue gem to have your tests start a pry session whenever something goes wrong. All you have to do is add a gem to your gemfile:

 group :development, :test do gem 'pry-rescue' end 

Then run your tests with the following flag:

 PRY_RESCUE_RAILS=1 rails test rails test test/integration/agendas_test.rb 
+1
source

Use -f .

In pure ruby, as you ask, it means ruby <file> -f .

In rails, this means rails test -f .

Minitest will check the terminal arguments for the -f flag, so the way it is called does not match -f .

0
source

Source: https://habr.com/ru/post/910310/


All Articles