Unit Testing In Python – No Dilemma

Tue 29 July 2008 by Garry Bodsworth

Unit-testing in Python today…

Having unit testing built into the language (or at least the standard library) is a good move. With an interpreted language like Python it is invaluable to test the various code paths.

It also helped me find some obvious bugs in my code, which I probably shouldn’t say in public, entirely because it is embarrassing. That is the first obvious benefit of unit testing. The next benefit is more subtle, you discover how to structure your code in a better fashion because you are thinking about how to test the individual parts of the code.

Unit testing is another option instead of the code checkers PyLint, etc, because the code paths are exercised providing you have written the test. Not perfect, but better than not doing code checking.

The scary thing is you end up with much more testing code than actual executable code. I remember reading somewhere that if that is the case then you are doing something right(!)