[TIP] Going From Untested Perl to Tested Python

Ben Finney ben+python at benfinney.id.au
Sun Feb 1 18:15:17 PST 2009


Noah Gift <noah.gift at gmail.com> writes:

> I am starting to convert a rather large code base from untested Perl
> to tested Python.  One idea I had was to write tests in Python, that
> tests the Perl code.  Once I have the core functionality worked out,
> the next step is to rewrite it in Python, and finish off unit testing.

This sounds like a very good approach, maximising the immediate value
of unit tests on the existing code, while setting the foundation for a
better overall situation.

> Has anyone else done something like this, and if so do you have
> recommendations?

A general recommendation for adding unit tests to an existing code
base: Expect that a great deal of the work will be in getting the
existing code to the point where it's even *feasible* to unit test it.

Code that has developed in the absence of automated tests is generally
much more tightly coupled, resulting in a very difficult time in
finding code units small enough to apply a unit test to. You will need
to re-work internal *and* external interfaces of the existing code
such that it can be parameterised with test doubles, instead of
assuming the overall context of the full running program.

If you remain aware of that necessary burden, you will hopefully be
less surprised by how large a proportion of the effort it turns out to
be :-)

-- 
 \          “When I get real bored, I like to drive downtown and get a |
  `\         great parking spot, then sit in my car and count how many |
_o__)                    people ask me if I'm leaving.” —Steven Wright |
Ben Finney




More information about the testing-in-python mailing list