Package Info

perl-Test-Magpie


Mocking framework with method stubs and behaviour verification


Development/Libraries/Perl

Test::Magpie is a test double framework heavily inspired by the Mockito framework for Java, and also the Python-Mockito project. In Mockito, you "spy" on objects for their behaviour, rather than being upfront about what should happen. I find this approach to be significantly more flexible and easier to work with than mocking systems like EasyMock, so I created a Perl implementation.

  • Mock objects

Mock objects, represented by Test::Magpie::Mock objects, are objects that pretend to be everything you could ever want them to be. A mock object can have any method called on it, does every roles, and isa subclass of any superclass. This allows you to easily throw a mock object around it will be treated as though it was a real object.

  • Method stubbing

Any method can be called on a mock object, and it will be logged as an invocation. By default, method calls return 'undef' in scalar context or an empty list in list context. Often, though, clients will be interested in the result of calling a method with some arguments. So you may specify how a method stub should respond when it is called.

  • Verify interactions

After calling your concrete code (the code under test) you may want to check that the code did operate correctly on the mock. To do this, you can use verifications to make sure code was called, with correct parameters and the correct amount of times.

  • Argument matching

Magpie gives you some helpful methods to validate arguments passed in to calls. You can check equality between arguments, or consume a general type of argument, or consume multiple arguments. See Test::Magpie::ArgumentMatcher for the juicy details.


License: Artistic-1.0 OR GPL-1.0-or-later
URL: https://metacpan.org/release/Test-Magpie

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.11-bp156.2.1 info GA Release 2023-07-22 15 SP6
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-Magpie
0.11-bp155.1.4 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Test-Magpie