[Melbourne-pm] Testing: stub modules and Test::More.

Daniel Pittman daniel at rimspace.net
Sun Mar 4 22:17:33 PST 2007

G'day.  I seem to be having a foolish day, and despite my best efforts I
can't work out how to get past a stumbling block in putting together an
automated test suite.

I have a module that is part of a large, heavy-weight and third party
product, so I want to test it independent of the main system.

It actually has very few dependencies on the real system, just two
functions in a single module, so I figured: easy!  Just stub out that
module in my test script and it will "just work."

Unfortunately I can't seem to make that work.

The existing module uses a bit of common third party infrastructure:

  use Product::Toolkit::General qw/string log/;

Now, even with a test script that reads (roughly):

  use Test::More plan => 27;

  package Product::Toolkit::General;
  ... stub version of the module here ...

I get the error:

  'Can't locate Product/Toolkit/General.pm in @INC'

I tried every darn thing I could think of, including the
Test::MockModule package, delaying the 'use' of my module until later --
even in a string eval statement -- and so forth.

Nothing!  Heck, I even tried setting the appropriate value into %INC to
try and fool the module loader into thinking that the third party module
was already loaded -- to no avail.

So, can someone help me out?  What on earth have I missed?

Digital Infrastructure Solutions -- making IT simple, stable and secure
Phone: 0401 155 707        email: contact at digital-infrastructure.com.au

More information about the Melbourne-pm mailing list