testing confusion

ok, i've written a fairly feature rich rails app and right now i'm catching up with myself by writing the tests for the damned thing.

currently getting the unit tests out of the way, but i have written one functional test also..

here's my problem.. when i run rake test one of my test units flunks horribly with a bunch of exceptions of the type "RuntimeError: Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id" ... but when i run the test on its own it passes with flying colors..

anybody know how this can be? i was under the impression that the tests are completely isolated from each other.

thanks in advance,

stuart

Hi Stuart,

Whenever I’ve had difference in behavior from running individual tests as opposed to the rake command they’ve usually been 1 of 2 things:

  1. The database isn’t populated with the test data (you need to run rake at least once)

  2. The fixture declarations aren’t correct. Make sure you’re loading all the related objects that you’re using in your tests and that the relationships are all correct.

Hope that helps, -Michael

thanks for the input guys.. so far still haven't figured this one out.. i did learn some things about testing though with your help. any other ideas?

stuart

still trying to resolve this issue, but i have uncovered something interesting. the issue is definetly that 2 of the fixtures just aren't getting along together. rake works fine with all test and either one of the culprits, but if the 2 are in the same test suite they start to complain.

still not sure how to remedy this or even what's going on.. i tried changing the filenames and see if it would change the order that they ran in and possibly rescue the test suite from the errors.. no luck

i think i need more information about what exactly is going on between unit tests.. i don't have any globals, class variables etc.. i've double checked that all fixtures that are needed are there (if i was missing one wouldn't the ruby test/unit/test.rb fail??)

really trying to get down to the bottom of this.. any other ideas?

thanks, stuart