Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: e54aae72b7
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (30 sloc) 1.1 KB
Test::Mock is a module that works alongside the standard Test module to
help you write tests when you want to verify what methods are called on
an object, while still having calls to undefined methods die.
You get started just as normal with the test file, but also add a use
statement for Test::Mock.
use Test;
use Test::Mock;
plan 2;
Imagine we have some class Foo:
class Foo {
method lol() { 'rofl' }
method wtf() { 'oh ffs' }
We then arrange to have a mocked instance of this class. This means that
instead of calls to lol and wtf actually resulting in the methods being
invoked, it simply logs the invocations.
my $x = mocked(Foo);
We can then take the actions that should result in some method calls.
Here we just make them directly, but you'd probably no doubt pass the
mock to other objects that will make calls on it.
When you're done, you assert that the things you expected to happen
actually happened.
*.called('lol', times => 2),
And that's it. :-) A few more features coming soon too.
Jump to Line
Something went wrong with that request. Please try again.