Should I Test My Fixtures?

I have a number of fixtures in my test suite. For example, with acts_as_authenticated and acts_as_state_machine, I created a number of users in different account states for use in functional testing. (Suspended users can not log in, etc)

Is it a good idea to run fixtures through tests to ensure that they conform to their ideals? EG: assert users(:suspended_user).suspended?

If so, where should these tests go? I currently have them in my unit tests.

Regards, --Dean

The fixtures should be perfect. There is no need to test them, as it is testing a test; paradoxical.

The fixtures should be perfect. There is no need to test them, as it is testing a test; paradoxical.

In this case it is more like testing inputs to a test, which imho is totally appropriate. A little quality control. A lot of my tests depended on the fixtures acting as advertised so I want a little assurance that the input data is correct.

It is especially handy with multiple developers that could make changes to the fixtures.

Any opinions?

--Dean

The fixtures should be perfect. There is no need to test them, as it is testing a test; paradoxical.

In this case it is more like testing inputs to a test, which imho is totally appropriate. A little quality control. A lot of my tests depended on the fixtures acting as advertised so I want a little assurance that the input data is correct.

It is especially handy with multiple developers that could make changes to the fixtures.

It's a bit of a 2 sided thing. On the one side if a test is broken because of some fixture change or similar it's helpful to see that the test broke because of some precondition rather than having to work that out yourself, on the other hand it can make tests rather long winded and/or more changing fixtures rather long winded. I don't think i'd ever do something quite like assert users(:suspended_user).suspended?, but in general

test_foo    assert some_precondition    do_foo    assert some_postcondition end

isn't necessarily a bad thing.

Fred

Using Dean’s latest reasoning, we should write a test that tests the test that we write for the fixtures, and a test for that, and a test for that…

It's silly to think of tests as some sort of rigorous proof of your system's correctness. Down that road are a bunch of extra, useless tests, and a lot of time spent omgquiscustodietipsoscustodes-ing. My tests do two things:

1. Increase my confidence that the system's still working after a change 2. Help me track down the unexpected consequences of a change

With that in mind, I don't see anything wrong with testing certain fixtures:

def test_important_fixtures_are_valid   %w(john paul george).each do |beatle|     assert(beatles(beatle.intern), "expected beatle fixture '#{beatle}' to be valid")   end end

~ j.

Rather than thinking that fixtures are part of the test I believe that *go into* the test. Just as a candy company tests the chocolate they put in their product it might be appropriate to assure fixtures are kosher.

I think Frederick Cheung's advice is more helpful and will combine it with useful fixture testing as suggested by John Barnette.

Regards, --Dean