Efficient python programming...

Delaney, Timothy tdelaney at avaya.com
Mon Jun 10 21:26:15 EDT 2002


> From: John J. Lee [mailto:jjl at pobox.com]
> 
> On Sun, 9 Jun 2002, Peter Hansen wrote:
> [...]
> > What tests do, however, is vastly increase your confidence in the
> > correctness of the code, and when written properly (in advance
> > of each small morsel of code that is written, and having been
> > shown to fail without that code) they are sufficient to deliver
> [...]
> 
> This point -- that tests should fail before they pass -- is 
> easy to forget
> about.  Thanks for reminding me.

It's one of the things that you need to be veryt rigourous about. It's very
tempting, upon receiving a bug report, to go charging into the code, finding
where the problem is, "fixing" it, then realising you need to test it.

Of course, by this time you can't write a test that *fails* with the
previous behaviour unless you go back to a previous version.

Always write a (correct ;) test that fails before "fixing" anything.

Unit tests may include 100% code coverage, but they rarely cover all
possible situations. When a new situation is found, the test should be
written.

Tim Delaney





More information about the Python-list mailing list