Adding static typing to Python

Delaney, Timothy tdelaney at avaya.com
Mon Feb 18 18:51:02 EST 2002


> From: ajeru at vknn.org [mailto:ajeru at vknn.org]
> 
> In Python I'd have to test the whole software suite including each and
> every branch in each and every if statement to be sure that I didn't
> forget something. To build such a test suite would take almost as long
> as it takes to build the whole software and I'd have to maintain the
> test suite as well. That's just unafordable.

This is precisely what you should be doing anyway. Changing a method
signature is a *minor* thing in any language compared to changing the
semantics of a method call. Your unit tests should have as close to 100%
coverage as possible (GUI work is one of the few cases where such coverage
often can't be met).

I can tell you that normally my unit tests take at least as long to write as
the supporting code - but it tells me if I change something fundamental.
Now, if it is a design change it may necessitate changing the unit tests.

I am currently looking at doing a study at work into using Python for unit
tests for Java code (using Jython and wrapping JUnit). There are a number of
advantages I see in it:

1. The unit test code will be shorter and more readable (incredibly
important). In particular, the ease of creating collections (tuples, lists,
dictionaries) are a major advantage here.

2. You don't need to entire framework in place to develop the test suite.
Currently, in order to write the unit test, every method that will be tested
needs to have at least a minimal implementation simply in order to be able
to compile the test. Using a python test suite, I could write the unit tests
ahead of time and get import errors, attribute errors, etc for missing
classes, methods, etc. This is a Good Thing(TM) - it allows for full
specification of the tests ahead of any actual coding.

Writing comprehensive test suites is not unaffordable - on the contrary, it
tends to mean that subtle errors are caught much earlier.

Tim Delaney




More information about the Python-list mailing list