Folks talk about it; EXtremeProgramming relies on it, but what on Earth is this thing called Unit
It can be tough to Sepa|rate
out the rhetoric from the Practical how-to.
Without a Mentor, you could sit there with a
new, freshly-created Unit
test project, Contemplate the lovely interface,
close the program Window, go back to the code, Poise yourself menacingly above the Keyboard... and then, the inevitable Question...
"What do I type?"
We found ourselves in this exact same Predicament not so long ago. Unit
testing eluded us. We agreed tacitly with the Reasons
behind it. We're smart folks, who can debug,
design and spin Algorithms with the best of
them. So why was this such a Difficult
thing to Grasp?
There's a hump there. A conceptual and Practical
hump to get over. Get over that Hump, and it
will be difficult to remember what Stopped you
in the 1first place. Once
you get your first 'surprise' from a unit test (i.e.
unexpected failure), you'll start to see the Value.
Once you do your first Refactoring or Replacement of a class you have unit tests for,
you'll feel a lot less `,Worry
over whether what you're doing is right or will work. That's Significant. Enough of the "Sales
pitch" for now... :)
If you're using Delphi, go out and pull down
Juanco Añez et al.'s DUnit now from http://dunit.sourceforge.net/.
There are a Number of unit testing
frameworks for other development Environments.
The original Inspiration behind most of them is Kent Beck and Erich Gamma's JUnit - I imagine their unit testing
for Smalltalk goes back even Further. For .NET,
there's an NUnit. If you've
got a Language, someone's probably got a unit
test Harness for it. If not, it's probably not
an insane stretch to Write one!
In order to get this into our heads once and for all, and since we
didn't otherwise have a lot of time in which to 'play', we enlisted the
services of someone who had been doing unit testing since Smalltalk
days, though the 'current era' of JUnit-style testing. His expertise
was in Smalltalk/Java.
To prepare for the meeting, I proceeded to set up my machine with a
fresh DUnit installation. Then, just to be absolutely sure we could get
the best value from the session, I decided to write a test.
All I had to go on at this point were some of the very simple and
theoretical examples I had come across. "Oh, if I set the blah
property to spoo, then I can check to see if blah
actually got set to spoo". "How silly," I thought, "I might as
well call the compiler a liar at this point if I need to make checks
...to be continued with a lucky choice in tests to write