# Should I Test My Fixtures?

**URL:** <https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740>\
**Category:** Rails\
**Created:** [February 11, 2008, 6:13am UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740 "2008-02-11T06:13:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 6:13am UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/1 "2008-02-11T06:13:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 7:03am UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/2 "2008-02-11T07:03:44Z")

</div>

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

On Feb 11, 2008 3:41 PM, Dean [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 6:03pm UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/3 "2008-02-11T18:03:23Z")

</div>

On Feb 11, 12:02 am, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 6:22pm UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/4 "2008-02-11T18:22:26Z")

</div>

On 11 Feb 2008, at 17:02, Dean wrote:

> 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

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 10:31pm UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/5 "2008-02-11T22:31:47Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 11, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/6 "2008-02-11T23:10:18Z")

</div>

On Feb 11, 2008 1:30 PM, Ryan B. (Radar) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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.

---

<div class="post-metadata">

**Author:** ![dean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3be4f8/32.png) [@dean](https://www.ruby-forum.com/u/dean)\
**Post date:** [February 12, 2008, 2:26am UTC](https://www.ruby-forum.com/t/should-i-test-my-fixtures/128740/7 "2008-02-12T02:26:52Z")

</div>

On Feb 11, 3:30 pm, “Ryan B. (Radar)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 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…

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 C.'s advice is more helpful and will combine it  
with useful fixture testing as suggested by John B…

Regards,  
–Dean
