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.
I appreciate the point you are making here. My concept, and I admit it is the concept of a complete Test::Unit newbie, was that the test case class was the unit of test, not the individual tests defined in the class. I guess I need to read up on the philosophy behind unit testing. Know any good references?
Also, I still don't like the idea of creating test objects over and over again, especially for tests that don't use them at all. Maybe my old (and now bad) habits formed over years of working on machines with limited resources are leading me astray, but -- at least for now -- I can't overcome my distaste for such extravagance.
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 is good advice. I'll try to heed it.
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.
You've almost convinced me, too
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.
I'm not sure what you mean by not correct. My results printout speaks for itself, doesn't it?
I agree that its being different on your box is troubling. It makes, as you point out, relying on any particular order indefensible.
One thing is for sure -- your comments are sending me back to redo my test case class. I'm not sure where I will take it (I'm still resisting you approach using setup), but I will change it so it doesn't rely on the order in which the tests are run. Oh well, I wanted to learn about Test::Unit and I'm certainly doing that
Regards, Morton
···
On Aug 30, 2006, at 4:00 PM, James Edward Gray II wrote:
On Aug 30, 2006, at 2:40 PM, Morton Goldberg wrote: