# Order of tests matters?

**URL:** <https://www.ruby-forum.com/t/order-of-tests-matters/50396>\
**Category:** Rails\
**Created:** [December 15, 2005, 10:48pm UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396 "2005-12-15T22:48:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pho3nixf1re](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pho3nixf1re](https://www.ruby-forum.com/u/pho3nixf1re)\
**Post date:** [December 15, 2005, 10:48pm UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396/1 "2005-12-15T22:48:14Z")

</div>

I have a problem with tests. I always thought that the order of tests  
doesn’t  
matter because the fixtures are reloaded before every test method.  
However, I’ve  
just discovered that this isn’t true.

This is a quote from the “Guide to testing the rails” howto:  
“… if we had another test method, we wouldn?t have 10 users on the 2nd  
test  
because they would be wiped out before being created…”

The last part of the quote indicates to me that the fixtures are  
reloaded before  
each test method.

Scaffold generates same basic tests for you, but these fail for me. My  
fixture  
for the things table has an entry for a thing with id = 1. The destroy  
test  
destroys Thing with id = 1 with Thing.destroy(1). The edit test tries to  
find  
the same object with Thing.find(1) and fails because the object it’s  
looking for  
has been deleted. But the fixtures should have been reloaded!! I don’t  
get it.

I’m using Rails 0.14.3 - perhaps this is only an issue here? Does 1.0  
address  
this issue? Am I just thinking about fixtures incorrectly, and in fact  
they are  
never reloaded between test methods? Do I have to do that manually with  
setup  
and teardown?

---

<div class="post-metadata">

**Author:** ![pho3nixf1re](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pho3nixf1re](https://www.ruby-forum.com/u/pho3nixf1re)\
**Post date:** [December 15, 2005, 10:54pm UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396/2 "2005-12-15T22:54:43Z")

</div>

I forgot to mention - you can get things to work by just having the  
destroy test  
run last. Things are done in alphabetical order, so changing the method  
name to  
test\_zzzzzz\_destroy will make things work. The order of tests should not  
have  
any effect on whether the test passes or fails - should it?

---

<div class="post-metadata">

**Author:** ![pho3nixf1re](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pho3nixf1re](https://www.ruby-forum.com/u/pho3nixf1re)\
**Post date:** [December 16, 2005, 11:01am UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396/3 "2005-12-16T11:01:16Z")

</div>

I just ran into this same issue today. Running Rails 1.0:

rails test  
cd test  
./script/generate person  
rake test\_functional

Gives me three errors of the kind

1. Error:  
test\_update(ServiceDeploymentsControllerTest):  
ActiveRecord::RecordNotFound: Couldn’t find Person with ID=1

When I comment out the test\_delete method, the scaffold-generated tests  
pass.  
The Person created by test\_create remains in the test database as  
well, even though other tests ran after test\_create.

Any ideas much appreciated.

cheers  
Gerret

---

<div class="post-metadata">

**Author:** ![pho3nixf1re](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pho3nixf1re](https://www.ruby-forum.com/u/pho3nixf1re)\
**Post date:** [December 16, 2005, 8:06pm UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396/4 "2005-12-16T20:06:37Z")

</div>

Gerret A. wrote:

> I just ran into this same issue today. Running Rails 1.0:  
> rails test  
> cd test  
> ./script/generate person  
> rake test\_functional
> 
> Gives me three errors of the kind

The guide and the docs should really mention this problem. Transactional  
fixtures were turned on by default in Rails 1.0, to speed up testing.  
Unfortunately the default MySQL database type (MyISAM) doesn’t support  
transactional fixtures…

The quick fix is to put the following line at the top of your test class  
(inside the class)

self.use\_transactional\_fixtures = false

The alternative fix is to change your table type to InnoDB (assuming  
you’re using MySQL)

alter table products type=InnoDB;

Then you won’t have to worry and your tests will be faster…

See this article for more details

[http://www.clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting](http://www.clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting)

---

<div class="post-metadata">

**Author:** ![pho3nixf1re](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba9def/32.png) [@pho3nixf1re](https://www.ruby-forum.com/u/pho3nixf1re)\
**Post date:** [December 16, 2005, 8:34pm UTC](https://www.ruby-forum.com/t/order-of-tests-matters/50396/5 "2005-12-16T20:34:40Z")

</div>

Thanks Kenny. I knew about the transactional fixtures, but had  
forgotten.
