Automating Your Unit Tests: Start-to-finish example

Thursday, February 7, 2008

Getting started with unit testing is hard for a lot of people. If you could count the number of people on January 2nd who say "This year I'm going to start unit testing", and then compare that with the number of people on March 1 who actually followed through, you'd get a graph that looked like... well, it'd look like the graph of the people who promised to start exercising, too. Hard stuff, or stuff that's perceived to be hard, requires lots of different motivators to turn the behavior into a habit. One potentially overlooked motivator to keep you unit testing is test automation. Why? Because it acts as a type of feedback loop. You're reminded every day (or several times a day) of the work you've put in. There's comfort in seeing the Success-to-Fail ratio improve over time. When you get an email from your test automation code that says "Successes: 5" on Monday and then the next Monday you see "Successes: 10"... that's progress. You've written tests. You're getting the green bar. It's basic slot machine psychology. So how do you automate? Simple: you spend 10 hours installing a continuous integration server, write a few hundred lines of ANT script, and bam, you're done. So, get to it! ......... What? Oh. You don't need that yet. You only have a few dozen tests and your boss is already up your a$$ telling you to quit testing and start programming (tee hee). OK, well, i guess you could just do it the easier way then. It's boring. It's plain-jane. And it certainly won't get you chicks. But it will get you automated tests and notifications and all that stuff. Without further adieu, here it is: simple test automation using good old CFAdmin scheduled task and some pretty simple code (that you can copy and paste). It'll take you longer to read this documentation than it will to have your tests automated. Good luck! --marc

No comments: