What to do instead of writing Unit tests (part 2)

Yesterday, I asked you to write down the value you get from unit testing, and also to write out your problems with it.

If you haven’t already done that, please do. You can hit reply in the comments, or email me, or you can tell your text editor.

The important thing is to actualize your expectations.

Ok, now that you’ve done that, how do you feel?

Has writing unit tests given you the value you’re looking for? Has it given you more pain than you were expecting?

If the answers are yes, and no (respectively), go about your business. Keep writing unit tests. At some point, you’ll hit the pain. It’s… inevitable.

For those of you that get value and pain from unit tests, that pain is something you want to hone in on.

That pain may be a general feeling of ennui, or it may be a specific class or area of the system you’re dealing with. But, today we’re going to focus on a specific part of a system you’re dealing with right now that causes you pain for writing unit tests.

For today’s assignment, I want you to do two things:

1. I want you to write down what that area of the system is supposed to do, from the consumer’s perspective (the user if the user interacts directly, or the expectations from whatever other part of your system consumes what that piece does).

2. I want you to eyeball its cyclomatic complexity. (if you have a piece of software handy that does this; great; if not, you can eyeball it).

Cyclomatic complexity is essentially the count of the number of independent paths or decisions that need to be made to traverse a piece of code.

Start at 1, and add one for every condition in if statements you encounter (case/switch is just another style of if statement). Now this isn’t exactly correct; but for our purposes it’ll do — we’re looking for a ballpark number.

Write down that number.

If you want to play with software that does this for free; I recommend FxCop, but there are others.

Also, it appears there’s a powershell script for using FxCop to generate cyclomatic complexity graphs. I haven’t tried it, but I should.

Next time, we’ll talk about what to do with this information. For now, it’s just important that you get that information.

Leave a Reply

Discover more from George Stocker

Subscribe now to keep reading and get access to the full archive.

Continue reading