I'm working with a web application that, normally, runs in mod_perl under Apache. A co-worker and I are trying to do some unit testing. Are there any good tools or techniques out there for mocking-up sessions and requests and the like that could help us exercise this code outside of the web server context?
If you're using mod_perl 1, there is Apache::FakeRequest which comes with mod_perl. It is not a complete mock of the request object, so you have to add some methods of your own. Even more if your code uses Apache::Request. Yet more for cookies and uploads. Mostly you're going to be spending a lot of time with Test::MockObject. Fortunately, the Apache object interfaces are pretty straight forward.
If at all possible, you should consider switching to a Plack based framework (Catalyst, Dancer, etc...) which provide far more robust testing and debugging facilities. If you're using mod_perl2, you're in luck! It's easy (relative to mod_perl 1) to wrap a mod_perl2 application with Plack. Plack::App::FakeApache does most of the work for you. Here is a discussion sketching out the various techniques and benefits.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With