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

minitest, ruby, testing

Solution

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.

Problem

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.

Original source