Unit Testing in Python

Tom Willis tom.willis at gmail.com
Fri Feb 11 08:00:05 EST 2005


I've had great experience doing Test Driven Development. Ideally you
would do it from the start, but it is great for refactoring as well.
In any language.

One of the pitfalls to look out for is to not get too hung up on it. 
In the end it's just a tool you use at your discretion. When I first
started doing it, I would get hung up on how the test framework should
look etc... almost as if I was architecting a system. It really slowed
me down.

I now take this approach...

1. what is the smallest piece of functionality that I want? (What to test)
2. what test will confirm I have this functionality?(How to test it)
3. how will I access this functionality.(Define the API)
4. write test
5. write code
6. run test.
7. repeat 4,5,6 until you're happy.

Frameworks like xUnit etc... just enhance the experience but are in no
way required in my opinion.
 
Another nice side effect is that your architecture design then comes
naturally and it is exactly what you need nothing more, nothing less.

I recently converted a very problematic data migration routine that
was written in Transact SQL by a consultant who liked to push the
limits of their chosen tool.

I wrote it in Python because I was predicting that no one could nail
down all the possible permutations of data that might come through. I
needed the ability for the routine to be flexible.

Anywho, using python and TDD I was able to get functionality
running/tested from minute 1 using only XEmacs and ipython.





On Fri, 11 Feb 2005 12:39:07 +0100, BJörn Lindqvist <bjourne at gmail.com> wrote:
> > put it) PyUnit project. I'm sorry if this is a obvious question or one
> > that has already been answered, but unit-testing sounds interesting and
> > I'm not sure where to start.
> 
> Hi Ryan. I belive this (http://www.xp123.com/xplor/xp0201/index.shtml)
> is a good way to learn about unit testing by practice if you already
> know the basics of it. It is written in Java but is easy to translate
> to Python. Unittesting really is great in Python, I try to use it for
> anything but simple and dirty hacks.
> 
> --
> mvh Björn
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


-- 
Thomas G. Willis
http://paperbackmusic.net



More information about the Python-list mailing list