Test::VirtualModule
This package allows you to generate perl modules on flight for unit-testing. This package is usable when you have complex environment with some tricky perl modules inside of it, which can't be installed without full environment. And you unable to write unit tests.
This module allows you to cheat and tell to perl that these modules already loaded.
# load virtual module use Test::VirtualModule qw/BlahBlahBlah::FooBar/; # import mocked module, it's ok use BlahBlahBlah::FooBar; # Mock constructor Test::VirtualModule->mock_sub('BlahBlahBlah::FooBar', new => sub { my $self = {}; bless $self, 'BlahBlahBlah::FooBar'; return $self; } ); # create object my $object = BlahBlahBlah::FooBar->new();
That's all.
Alows you to mock subroutines of specified module.
Test::VirtualModule->mock_sub( 'SomeModule', get_property => sub { return 1; }, ); SomeModule->get_property(1);
To install Test::VirtualModule, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::VirtualModule
CPAN shell
perl -MCPAN -e shell install Test::VirtualModule
For more information on module installation, please visit the detailed CPAN module installation guide.