When is unit-testing bad?

Jeremy Bowers jerf at jerf.org
Thu Jul 3 22:06:44 EDT 2003


On Thu, 03 Jul 2003 15:47:56 +0300, Edvard Majakari wrote:
> Which reminds me: I've seen two web unit testing frameworks, one which was
> by the originial PyUT author, and the other that seemed more complete,
> though not so well documented either.
> 
> I've fancied developing one myself - so I'd like to know what kind of
> things should I take into account before trying such a largish project?  I
> know that it is hard to test Web-based applications, for one thing - the
> user doesn't usually type GET parameters to the URL, while doing so could
> be the only possible way to do automated web site testing. Ideas/comments?

Well, technically I'm using Perl to do this but this message will apply
equally to Python unit testing on the web; it's not language specific.

We're using mod_perl, and I'm using Test::Unit, which is a testing
framework for Perl deliberately set up to look like JUnit, as Python's
unittest is. What I'm doing is implementing an Apache Request faked-up
object (which I later found existed in the form of the Perl module
Apache::FakeRequest, but I think my own solution is better suited to our
needs anyhow), and then going ahead and calling the Apache handlers
directly with that object. It's tedious to construct the object if you
can't find one pre-made, but it's easy.

I've got mine set up so it records what is printed with it, so it can do
things like extract necessary data from the output if necessary. I also
have it set up to easily pass form parameters in according to the system
we use.

Once you do this, there's not a *whole* lot of difference between normal
unit testing and this. In fact, you'll have an even easier time then me if
you aren't grafting unit testing onto a multi-year old system with little
to no functional separation (for practical purposes).

In the end only the very, very last step (converting your output to HTML)
is hard to test meaningfully, since it's hard to program whether it's
doing what it's supposed to do in an automated fashion. But even in a web
application, that's not the majority of the code, unless *all* you are
doing is wrapping a shell around somebody else's library. Everything else
is fairly straightforward.




More information about the Python-list mailing list