Jan 16, 2008 / software ~ productivity
Unit Testing and Brian Tracey

I've been practicing TDD and Unit Testing for many years and have found it a rewarding process. However, I'd never really asked myself "Why do I find this rewarding?".

Amongst other places, the answer might be found in the words of the world famous sales guru - "Brian Tracey"! Brian is a guy who writes a lot of books about sales, marketing and personal productivity. Like many other productivity gurus, Brian teaches the reader a number of "principles" or practices that will hopefully lead them to success in various areas of their life. Much of these principles are simple and almost common sense, but I personally find I don't always remember common sense!

I've always said "Most good practices are common sense, but common sense practices are useless unless you apply them constantly and systematically!"

But how does all this relate to unit testing? Well, in a few ways perhaps...

####Focus According to Brian (and other productivity gurus), focus is a very very important part of productivity. Focus allows us to concentrate on one thing without distraction. Also, I've found that once you start being aware of where you're focusing your time, it pays greatly to actually go on to find the things really worth focusing on. The end result is that you spend more time doing the good stuff, in a highly focussed way.

Writing tests and making them pass really encourages us to focus; Tests usually exercise a small area of code, and whilst writing the code and making the test pass, we're focusing on a very particular problem. You can achieve focus without testing, but I find it interesting that the concept of focus is "built-in" to the practice of unit testing.

####Goal Oriented Brian promotes that goals are essential to success. We need to have absolute clarity about what we're aiming for. By main having clear, concise goals, is that you can easily make decisions that move you in the right direction. I've often found myself being uncertain about something because I don't really know what I want to achieve.

Making a unit test pass encourages us to have a very specific goal. When writing test and trying to get the "green bar", you have a very specific end result in mind (the green bar!). Furthermore, we have sub-goals, which is to get our test assertions to hold true. So, a unit test can be seen as a series of goals. Again, it's cool that this principle is built right in to the practice of unit testing.

####Minimal Distractions Productivity experts also say that we should remove distractions when performing any task. That means closing your email before starting to code, or turning off the Tv whilst reading. Distractions obviously pollute the quality time we give to our activities.

The practice of unit testing has evolved to rule out as many distractions as possible. For example, they don't require us to mess about with our applications GUI to recreate errors. Instead, we work in a small, clutter free area of the code (our test fixtures) that is dedicated to the job in hand.

You may also like...