mocked(3pm)

mocked3pm

Use mocked libraries in unit tests

Usage

  # use a fake LWP::Simple for testing from t/lib/LWP/Simple.pm
  use mocked 'LWP::Simple';
  my $text = get($url);
  # use a fake WWW::Mechanize for testing from t/mock-libs/WWW/Mechanize.pm
  use mocked [qw(WWW::Mechanize t/mock-libs)];

Overview

Often during unit testing, you may find the need to use mocked libraries to test edge cases, or prevent unit tests from using slow or external code.

This is where mocking libraries can help.

When you mock a library, you are creating a fake one that will be used in place of the real one. The code can do as much or as little as is needed.

Use mocked.pm as a safety measure (be sure you're actually using the mocked module), and as a way to document the tests for future maintainers.

Variables

real_inc_paths

The real @INC that we are over-ridding is stored here while we are loading the mocked library.

Functions

import

With a package name, this function will ensure that the module you specify is loaded from t/lib.

You can also pass an array reference containing the package name and a directory from which to load it from.

Mad creds to

Ingy döt net, for only.pm

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 3 times.

  1. 6.0–9
  2. 10
  3. 11
  4. 12–13

Author

Luke Closs, "<cpan at 5thplane.com>" Scott McWhirter, "<kungfuftr at cpan.org>"

License

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

From libmocked-perl 0.09-6 in Debian 13 (Trixie). Parsed by carta from the page's man source.