[TIP] Testing in General

Ben Finney ben+python at benfinney.id.au
Tue Mar 31 17:21:39 PDT 2009


Michael Gratton <michael at quuxo.com> writes:

> Hi David,
> 
> On Tue, 2009-03-31 at 18:20 -0400, David Blewett wrote:
> > I was going to start by putting in coverage testing, so that I can
> > start adding tests to the most active sections of my codebase. Any
> > advice is appreciated.
> 
> Just get some initial tests running, just a couple. This is
> generally the biggest hurdle since it takes time away from doing
> what you really want to do — hacking on your app. These initial
> tests also serve as templates for adding more, making it easier to
> do so.

Also important is to realise that a code base which has evolved in the
absence of unit tests will very likely be difficult to test.

By which I mean, it will likely be architected in such a way that its
internal interfaces are not loosely coupled, are too wide, do too much
per unit, et cetera. One of the big advantages of focusing on
testability of the code will be uncovering issues like this that have
lain dormant in the code.

For this reason I heartily agree with the advice to start by just
adding one or two tests — but be scrupulous in ensuring the tests
assert a *single* true or false statement about the code's behaviour.
This may be shockingly difficult if the code is currently not designed
well for this kind of inspection, but it is essential if your tests
are to be useful in future debugging.

You will learn a lot about your code from a different perspective,
i.e. that of using your code's interfaces. You will likely need to
re-factor large swathes of the code in order to get easily-tested
interfaces; this is time well spent.

Actually *writing* the tests will, I predict, be a miniscule portion
of this initial time.

-- 
 \      “Some forms of reality are so horrible we refuse to face them, |
  `\     unless we are trapped into it by comedy. To label any subject |
_o__)        unsuitable for comedy is to admit defeat.” —Peter Sellers |
Ben Finney
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.idyll.org/pipermail/testing-in-python/attachments/20090401/c134b5a8/attachment.pgp 


More information about the testing-in-python mailing list