Code correctness, and testing strategies

Roy Smith roy at panix.com
Sat May 24 18:16:04 EDT 2008


David <wizzardx at gmail.com> wrote:

> While it is possible to describe all problems in docs, it can be very
> hard to write actual test code.
> 
> For example: sanity tests. Functions can have tests for situations
> that can never occur, or are very hard to reproduce. How do you unit
> test for those?

In some cases, you can use mock objects to mimic the "can never happen" 
situations.  But, you are right, there are certainly cases which are 
difficult or impossible to test for.  TDD is a very powerful tool, but it's 
just that: a tool.  It's not a magic wand.

My suggestion is to make using TDD a habit, but don't turn it into a 
religion.  You will undoubtedly find places where it's just the wrong tool.  
Don't let the fact that it can't do everything keep you from using it when 
it makes sense.



More information about the Python-list mailing list