Python Unit Testing
One of the projects that has been on my Someday/Maybe list for a while has been to learn about “Unit Testing”:http://diveintopython.org/unit_testing/index.html and “test driven development”:http://www.kryogenix.org/days/2004/06/14/development950408240368.
Most of the little utilities I use at work to make my life easier were written a few years ago in Java. This year I’ve started to convert some of them into “Python”:http://www.python.org as an aide to learning it. Last month I converted a small program that automatically downloads customer’s testcases from an FTP site onto my harddrive. When the service request is closed, it automatically archives the testcase (aside: the manual process to do this is very tedious and slow. The people I work don’t seen to write any code to automate their jobs in any way. Is this something you do? Or do you never have the time to write hacks that will make you job easier?)
When I rewrote this in Python, I thought it would be a good exercise to learn unit testing, however the ease of Python meant I just dived straight in and had written 95% percent of it before I’d even remembered about unit testing. I finished the code off and made a note to read the unit testing chapters and then add unit testing to the code afterwards.
I’m reading through the chapters now and come to “these basic points about unit testing”:http://diveintopython.org/refactoring/summary.html :-
bq.:http://diveintopython.org/refactoring/summary.html There are unit testing frameworks for many languages, all of which require you to understand the same basic concepts:
* Designing test cases that are specific, automated, and independent
* *Writing test cases before the code they are testing*
* Writing tests that test good input and check for proper results
* Writing tests that test bad input and check for proper failures
* Writing and updating test cases to illustrate bugs or reflect new requirements
* Refactoring mercilessly to improve performance, scalability, readability, maintainability, or whatever other -ility you’re lacking
I think I’ll start again.