XpdWiki
Set your name in
UserPreferences Edit this page Referenced by
JSPWiki v2.0.52
![]() ![]() |
This is an automation of a testing pattern for injecting a MockObject into a class under test when it normally creates such an object internally. In brief... One way of getting a mock into an object that itself creates another object is to move the creation to a separate method. When testing, the class under test is subclassed and the creation method overridden to create the desired mock instead. The most flexible version of this is one where the overridden method can have expectations and returns set just like a mock. As the method overlay is itself an act of mocking (in this case only one method) I called it partial mocking. Like mock objects, this is susceptible to automation using generation for the subclass. The PHP SimpleTest unit tester includes such a code generator and so I have explained it in more detail here http://www.lastcraft.com/partial_mocks_documenation.php Is this a good idea? I only really use PartialMocks for mock injection, although it could be extended for testing less than a class. Breaking class level testing kind of degrades the OO style upgrade you get from using MockObjects. When used for getting mocks into objects it is a compromise between adding extra optional parameters (or overloaded methods) which produces very visible test code, and passing in factories for all creation which could trigger a long chain of refactorings. This last solution is the most highly factored (and favoured by SteveFreeman), but isn't sometimes overkill? - MarcuS
|