I've been making a more concerted effort to write test code as part of new
modules and was doing pretty well. Then I started working on something and
The Fever took hold - I just kept grinding out code. After a couple of
weeks, I realized I could do a really, really big improvement with a
rewrite. (Consolidating a bunch of similar things into one thing.) It's
going to be so much better! Just wait and see, it really will be. But then
I wasn't sure if it was really working right...and I didn't have test
cases. Ouch.

So, I went back to basics. In this case, I've got a multi-process V16 bit
of code that's all about message passing. So it's hard to test. I figured
I'd start with 1) the most basic tests (simple permissions-like tests), 2)
the easy, function-like tests (validating parameter counts, inputs, and
outputs), and then 3) the hard stuff.

#1 went fine, no problems.

#2 the simple functions...my brain said "that stuff is fine, there's
nothing to worry about there." I figured I'd do the right thing and bang
out the test cases anyway. I ran them and got a bunch of bugs. I figured it
was something I'd screwed up in the test cases/code itself. It took me some
time to realize that, no, I'd left an enormous gaping hole in my code that
wasn't visible at first sight. That lead to finding a subtle behavior in
one of my validation routines that could make a bunch of other code behave
unexpectedly. (I had a couple of hundred other tests cases I could run on
that and did find one change I had to make. It was just a change in the
error name you get for a specific sort of bad input, but still...it was a
change.)

So, just a good reminder of how important it is to have test code. I mean,
I just found some meaningful bugs and I haven't even gotten to the hard
part yet (#3.) It's so much easier to test the hard parts/integration when
you've got the basics nailed down. Otherwise, you can end up chasing a bug
all day only to find it was all or in part coming from something silly.

Test code can be hard to write and can have it's own problems. It's also
easy to not develop the tests that break your own code. Still, beats *not*
having test code.
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to