Hey,
Does anyone know a way to do the equivalent of @AfterClass in
Test::Unit? I need to execute some code once after ALL the test_*
methods in a Test::Unit::TestCase have run (teardown runs after EACH
method).
The reason I need to do this is that Rails leaves old fixture data in
the DB after each TestCase is run. This just doesn’t seem right to me,
as I think each TestCase should start with the same state, but that is
another issue. The immediate problem is that this can cause tests to
fail if there are foreign key constraints. For example:
TestCase1 < Test::Unit::TestCase
fixtures :testa, :testb
end
TestCase2 < Test::Unit:TestCase
fixtures :testa
end
If testb has a foreign key that depends upon testa, the second
TestCase will fail since it will only try to delete from table testa
and there are records in table testb that depend on testa.
Cliff Moon of PhillyOnRails wrote a plugin
(http://agilewebdevelopment.com/plugins/foreign_key_fixtures) to solve
this problem, but the svn repository seems to be down.
Another note: I only noticed this when setting up my cruisecontrol.rb
for my project. The normal “rake test” task sets up the Test DB schema
from schema.rb which ignores foreign keys. So if you have foreign keys
in your DB be aware that there is a good chance you are running your
tests without them.
Any ideas?
- Patrick J.