Mocking up Apache session data for unit testing

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.

链接地址: http://www.djcxy.com/p/9554.html

上一篇: 如何修复Vim在Python中对长行的行分行为?

下一篇: 嘲笑Apache会话数据进行单元测试