Integrating Apache::Test and Test::More

When I decided to use Apache::Test to test some aspects of my web application framework, I had a difficult time initially going through the documentation. Most of what I found assumed 1) the module was being developed in the Apache namespace, and/or 2) development was starting from scratch. Neither assumption was true for my case.

I already had several hundred tests written using Test::More to test such things as data validation, text and date formatting, and some rather generic OO data store and exception modules. These tests provided a solid foundation, but because my framework depends on HTML::Mason and mod_perl, there were some pieces of functionality that could only be tested when talking to a live web server. However, I didn't want to wed myself to Apache::Test, since there are a number of features that work fine in an offline context. So the question became: how can I add Apache::Test without breaking or having to rewrite the tests using Test::More?

I spent a day or so doing numerous Google searches and reading two good introductions to Apache::Test, here and here. But I didn't find what I was looking for until I stumbled across this post on Christopher Laco's blog. From there I found the e-commerce module he was developing, and looking at his testing code helped me figure out the rest.

In a nutshell, we test for Apache::Test in Makefile.PL. If we can use it, we pull in Apache::TestMM, which will override ExtUtils::MakeMaker's test and clean routines. This means that if Apache::Test isn't installed on a system, make test will work as usual, and there will be no attempt to start up Apache. For the test scripts that require Apache::Test, a little bit of code at the top will insure that these tests will be skipped if Apache::Test isn't present.

If you are looking to integrate Apache::Test and any other offline testing framework, I recommend looking at Laco's code as well as my own, and dig through the extensive documentation on perl.apache.com. One thing I needed to do that Laco didn't is get a Mason-enabled Apache working, and there were a few unexpected "gotcha's" there that my code might help you with. Good luck!