Test::Unit mocking the db

Think about what value you will really get by testing without the database. You will be testing in a different environment than the code will really run in. You will have to do quite a bit of work to create this fake environment. All to isolate a bit of logic that you can test just as well with the database present. While some advocate this type of isolated unit test, it seems too extreme to me. But then, I find most of my testing is more on the functional scale than unit test anyway, as the logic of a single class without associations seems pretty boring and only in a few cases is worth testing beyond basic functions that are implemented in AR code anyway. The bottom line is do what works for your project, do not be dogmatic about it.

Michael

Jay Fields has talked a lot about this topic. While I agree with the points you’re discussing, I do believe that there are times when you might want to test without the db… one reason might be to speed up the tests. See these posts for more info.

http://blog.jayfields.com/2006/06/ruby-on-rails-unit-tests.html
http://blog.jayfields.com/2006/09/rubyrails-unit-testing-in-less-than-1.html

http://blog.jayfields.com/2007/05/testing-unit-test-of-functional-test.html

Just thought I’d chime in :slight_smile: