assert_nothing_tested
Published 2012-01-11 @ 12:00
Tagged minitest, rails, ruby
Check this rails test out:
1 2 3 4 5 6 7 8 9 10 11 12 |
def test_remove_column_with_multi_column_index ActiveRecord::Base.connection.create_table(:hats) do |table| table.column :hat_name, :string, :limit => 100 table.column :hat_size, :integer table.column :hat_style, :string, :limit => 100 end ActiveRecord::Base.connection.add_index "hats", ["hat_style", "hat_size"], :unique => true assert_nothing_raised { Person.connection.remove_column("hats", "hat_size") } ensure ActiveRecord::Base.connection.drop_table(:hats) end |
The file this test came from is chock full of tests written just like this one. What exactly is it testing? The test name implies that it is testing remove_column when there is a multi-column index. Does the test ensure that remove_column does the right thing? No.
Better yet, here’s how to make it pass:
Tada! No exceptions raised!
This is exactly why minitest doesn’t have assert_nothing_raised
. You wind up with file after file of useless junk tests.
tenderlove recently converted the rails tests from test/unit to minitest and had to get these tests working since they were all calling assert_nothing_raised
. Here is his implementation:
Certainly easier to do this than to go through all the tests and remove the call (never mind adding real assertions to make sure something is actually being tested).