# Unit testing methods interfering with each other

**URL:** <https://www.ruby-forum.com/t/unit-testing-methods-interfering-with-each-other/49673>\
**Category:** Rails\
**Created:** [December 7, 2005, 2:56pm UTC](https://www.ruby-forum.com/t/unit-testing-methods-interfering-with-each-other/49673 "2005-12-07T14:56:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nmkolev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nmkolev](https://www.ruby-forum.com/u/nmkolev)\
**Post date:** [December 7, 2005, 2:56pm UTC](https://www.ruby-forum.com/t/unit-testing-methods-interfering-with-each-other/49673/1 "2005-12-07T14:56:29Z")

</div>

Hi all,

I am following the Agile Rails book and have a problem with unit  
testing. Here is my products test file:

require File.dirname( **FILE** ) + ‘/…/test\_helper’

class ProductTest \< Test::Unit::TestCase

fixtures :products

def setup  
@product = Product.find 1  
end

def test\_load\_in\_db  
assert\_kind\_of Product, @product  
assert\_equal 29.95, @product.price  
end

def test\_destroy  
@product.destroy  
assert\_raise(ActiveRecord::RecordNotFound) { Product.find  
@product.id }  
end

end

According to the book this should work, as different tests are not  
dependent on each other, e.g. the destroy test should be independent  
of the load\_in\_db test. I do howeveg get this after running the test:

:!ruby test/unit/product\_test.rb  
Loaded suite test/unit/product\_test  
Started  
.E  
Finished in 0.259161 seconds.

1. Error:  
test\_load\_in\_db(ProductTest):  
ActiveRecord::RecordNotFound: Couldn’t find Product with ID=1  
/opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/  
active\_record/base.rb:428:in `find' test/unit/product_test.rb:8:in`setup\_without\_fixtures’  
/opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/  
active\_record/fixtures.rb:522:in `setup' /opt2/local/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/ active_record/fixtures.rb:520:in`setup’

2 tests, 1 assertions, 0 failures, 1 errors

If I remove the destroy test everything works as expected?

Any ideas as to why this is happening?

Many thanks in advance,  
Nicky

---

<div class="post-metadata">

**Author:** ![nmkolev](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@nmkolev](https://www.ruby-forum.com/u/nmkolev)\
**Post date:** [December 7, 2005, 3:37pm UTC](https://www.ruby-forum.com/t/unit-testing-methods-interfering-with-each-other/49673/2 "2005-12-07T15:37:28Z")

</div>

OK, found it. Has to do with the fact that Rails 0.14 switched to  
transactional fixtures which my MySQL table type did not support.  
More details here: [http://www.clarkware.com/cgi/blosxom/](http://www.clarkware.com/cgi/blosxom/)  
2005/10/24#Rails10FastTesting

Cheers,  
– Nicky
