Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minitest #setup and #teardown not called when test run via Rake

I have a MiniTest suite. I'm using the basic Minitest::Unit::TestCase, not specs. I have setup and teardown methods defined in my TestCase subclass. They work perfectly when I run a test file like so: ruby test/whatever_test.rb. But when I run rake test, setup and teardown are not called. The relevant portion of my Rakefile is:

require 'rake/testtask'

Rake::TestTask.new do |t|
  t.test_files = FileList['test/*_test.rb']
  t.verbose = true
end

Why wouldn't the setup and teardown be run when Rake::TestTask is used?

I'd paste the test case code into here, but there's quite a lot of it. I'll certainly paste in some subset of it, if there's a particular section you'd like to see.

I'm running Minitest 4.3.2 on Ruby 1.9.3-p194.

like image 607
rlkw1024 Avatar asked Nov 30 '12 06:11

rlkw1024


2 Answers

The problem was that another test case was overwriting the setup and teardown methods. I had accidentally given two test cases the same class name, which is why the overwriting happened. Naturally, this error didn't happen when I ran a single test case, which explains the difference in behavior when using Rake.

like image 195
rlkw1024 Avatar answered Nov 11 '22 01:11

rlkw1024


In my case, I was writing tests for socket communication and had added a helper method named send. Since MiniTest uses send internally to call the teardown methods, it was instead calling my own send instead of the method-dispatch.

like image 1
Phrogz Avatar answered Nov 11 '22 00:11

Phrogz