Hello! Since I have what is probably and X/Y question, I'm going to describe both.
Context: I am developing unit tests for a Catalyst application. The Model is strictly relational, and consists of a straightforward Moose object many (100+) subroutines spread out over 15 or so Roles, but with associated SQL code somewhat specific to a database that I can't just make a little clone of for testing. I already have a system for testing this module that I am happy with. With that done, I would prefer to test the rest of the server code path with a fake DB object.
This would be roughly a "Mock" object, but I sometimes need it to be sensitive to input parameters, so call it "Mock+". It's technically easy to build such a thing, but given the large number of methods and the variety and sometimes complexity of the return values, I think it would take quite a bit of time.
I would prefer a record/replay solution like the following:
Record: One class takes another as a constructor argument, and then instantiates that object and "impersonates" its interface. When methods are called, it records the method and arguments as a "key", and return value as a "value". (Repeated keys can overwrite or discard a different return value -- it doesn't matter.) This goes to some file format either as the methods are called or at all at once when a method is called or the object is destructed.
Replay: Another class impersonates the same interface but doesn't instantiate the object. Instead, it turns the method/argument combinations into keys and returns the corresponding value if present. Otherwise it calls a default function (perhaps passing some version of the key, but I don't need that).
Return values need not include any function pointers, blessed objects and such. Parameter values of those types can just be treated as a string encoding the function or class name. Compromises such as turning the "key" into a unique string and storing an MD5 are fine.
So: 1) Does such a system already exist? And if not, 2) what projects/CPAN packages etc. would provide a useful reference or 3) what are the pieces with which such a (not necessarily CPAN-ready) system could be whipped up quickly?
In reply to Mock+ object with recording? by skef
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |