On May 9, 2006, at 4:19 PM, Kian wrote:> Now let''s say I run write a test for customer''s phones.
It loads
> fixtures for
> phones and customers. Except that it will fail trying to delete the
> existing
> customers, because they still have dependent addresses tied to them
> in the
> database. End of test. Crash & burn.
We could have fixtures wipe data after each test run. However,
transactional fixtures were implemented to improve testing speed --
we''d be right back to full insert/delete per test case (though better
than per method, true.)
> I could add :addresses to the fixtures call in the phone functional
> test. But 1)
> addresses have nothing to do with phones except that they both
> belong to
> customer, and 2) following this logic, I''ll soon have to load
> nearly every
> fixture in the system for most functional tests.
What if your pristine test data were available to all your tests
without making any fixtures declarations?
> Am I doing something wrong here? This seems like such a glaringly
> obvious goof
> that my assumption is that I''m using fixtures wrong.
What''s the
> proper way to
> use fixtures and insulate test cases from each other?
You aren''t. Fixtures remain "live" after testing and assume
you''ll
manage your foreign keys appropriately. Experiment with declaring
them all on a common base class and removing them from your
individual test cases:
class MyApp::TestCase < Test::Unit::TestCase
fixtures :addresses, :phones, :customers, ...
end
Or even rework your rake tasks to obviate fixtures altogether (e.g.
createdb -T fixtures test).
Having to declare fixtures at all, much less worrying about their
ordering and dependencies, is the real problem.
jeremy