From: Jim Weirich Date: 2003-06-03T10:30:00+09:00 Subject: Re: Unit Testing Style On Mon, 2003-06-02 at 16:08, Eric Schwartz wrote: > I know I should have written my tests first, but I didn't, so now I'm > trying to do them after the fact. I'm running into a few style > questions, though, not being used to the Test::Unit style of testing: > > 1) I have several test cases that do multiple assert_* calls. Is that > a Good Thing, a Bad Thing, or not something that's even worth > worrying about? Usually it's things like "Was the file created? > Does it contain data of the right format? Is the data correct?" Just remember that the test method will terminate with the first failing assert_*. So if you have a lot of them in a single method, you could have multiple failures hiding behind a single failure. > In one case, however, the test case is "run a command remotely that > logs to yet another remote database, and verify the command was > run, output was generated, logged to the right database with the > right timestamp, from the right machine, etc., etc., etc." I try to keep the external environment as simple and self contained as possible. I want to run the unit tests and KNOW everything is ok. If my tests depend on a lot of external resources, then failure may mean a problem with the code or a problem with the environment. I would rather spend time working on the code than tracing down environment problems. Sometimes you DO need to talk to external resources (e.g. databases, servers, etc.). I usually isolate these tests in their own area (usually a separate Rake/Make target). Then I can run the unit tests to check the code as often as I want and get a lots of "feel good" karma. And then I can run the environment dependent tests separately to make sure I still can talk to the outside world. > 2) How do people generally feel about interactivity in test cases? Evil! Don't do this! Never (at least in unit tests). If you REALLY need some interactivity, I would move it outside the unit tests. > Other than that, I'm enjoying Test::Unit quite a lot. Great! -- -- Jim Weirich jweirich@one.net http://jimweirich.umlcoop.net --------------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)