Friday, April 24, 2009

Unit tests as design documentation?

First, one thing I forgot to mention yesterday: the video card in my computer died, which is part of the reason why I wasn't blogging. The computer would have an acid-trip of sorts after a while and become unusable. I just got it replaced today with a $16 Nvidia card and it's working quite nicely. The main reason I got this card, besides the fact it was cheap, was that it uses passive cooling. God, this thing is so much quieter now...

Now, back to the main topic. After doing a bit more D coding yesterday and a little earlier today, I had an interesting thought after a couple of us talked about self-documenting code: could unit tests be used as design documentation? Think about it: if you design everything properly, your tests pass. Your tests should reflect the expected results of your methods/functions/whatever. I my case, since I'm trying to build an FSM, each test essentially documented the new state the FSM would enter based on the current state and any other inputs.

Granted, not all of your design is reflected in just unit tests, but a good portion could be. Combine this with some good documentation comments, and you've essentially provided design documentation in your code.

This is definitely something to think about because I'm thinking that the better way to document your software is in your software. If nothing else, your design is where your code is, so you have everything you need all in one place. Unfortunately, I don't know how to embed pretty diagrams in source code :-)

Labels: ,

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home