From: James Edward Gray II Date: 2006-08-31T05:00:11+09:00 Subject: Re: [QUIZ] DayRange (#92) Test::Unit gotcha On Aug 30, 2006, at 2:40 PM, Morton Goldberg wrote: > Thanks for trying to help, but if I understand how setup functions, > your modification defeats my requirement that the test objects be > created once and once only. As I understand it, setup will run > before EACH test and the test objects will be created over and over > again, even for test_bad_args where they are not needed at all. My opinion is that this is a very good thing. Tests should work in isolation as much as possible. You are testing one small part of the whole, to verify correctness. When you start sharing details between the tests you tie them right back into a complete system again and that's what unit testing is trying to avoid. Requiring that tests be run in a given order is just too fragile. When I do require that some tests work sequentially, I do it like this: def test_me_first # ... end def test_me_second test_me_first # ... end I only feel safe counting on the order when I get to say what the order is, using the above. This does extra work, as you complained about with my implementation of setup(). Ruby doesn't mind the exercise though and as long as she can do it quickly, I don't either. Besides, it shoots that test counter right on up! (Makes me feel great, "These tests are just flying by...") > Renaming test_valid_args to test_args is not only simpler, it meets > the requirement of parsimony of test objects. I'm very convinced this is the wrong way to go. You are relying on an implementation detail of Test::Unit here, that could change at anytime. That could cause your tests to start magically failing at some point down the road. I also don't believe you have the order correct. Your tests run as expected on my box with no modification to the method names. I haven't gone into the source of Test::Unit to determine why this is, but it could be that the methods are hashed in which case you can't count on any order at all. James Edward Gray II