13

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

Minitest reports summary of execution when it completes executing all tests. The Exceptions that were encountered are also printed towards the end of the execution. I find it difficult to debug when something unexpected fails as the context of execution is lost. The exceptions I am running into are not deterministic.

Is there a way to make Minitest runner to stop execution of tests on exception or assertion failure?

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

wanderer
  • 131
  • 1
  • 4

5 Answers5

4

try rails test -f will do it. It means abort test run of first failure or error.

Lou Zell
  • 5,255
  • 3
  • 28
  • 23
r31n4ard
  • 81
  • 4
3

I think you mean to have a "fast fail" option available. I found the fail_fast for minitest (Test::Unit): Immediate backtrace & exit article, but that's out of date (still covers what can be done). I think you'll need to monkeypatch your testing library to enable this option. I found a Gist showing how to add a simple fail-fast option to minitest/turn/minitest-rails so that might get you on the right track. I understand your problem is to do with the first article I've referenced:

When I run the Test::Unit suite in my Ruby on Rails 3 project through rake test and a test is failing, the default behavior is to just print “F” or “E”, keep running until all the tests are finished (while I twiddle my thumbs), and only then print out a stack trace.

2

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

Community
  • 1
  • 1
Ari
  • 1,974
  • 19
  • 30
1

It does not directly answer the question, but might be very useful.

You could use pry-rescue gem so that your tests will launch a pry session whenever something goes wrong. All you have to do is to add the gem into your Gemfile:

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

Then launch your tests with the following flag:

PRY_RESCUE_RAILS=1 rails test rails test test/integration/agendas_test.rb
Flavio Wuensche
  • 9,460
  • 1
  • 57
  • 54
1

Use -f.

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

In rails, this means rails test -f.

Minitest will check the terminal's arguments for the -f flag, so how you call it appears to not be relevant to the -f flag.

RWDJ
  • 734
  • 8
  • 13