[Mockbox 2.2] Spies on existing methods


I have some code that uses a collaborator. As I’m doing an integration test I want to use the actual methods of the collaborator, but I would like to verify that they are called. Is this possible?

Example of CUT:

void function doSomething(foo){
// some code here then…
local.foo = variables.collaborator.callMe(local.foo);


Example Test:

function test_it(){
local.mocked = createMock(“com.foo. collaborator”);
variables.CUT.$property(“collaborator”, “variables”, local.mocked);
assertEquals(1, local.mocked.$count(“callMe”));
assertEquals(1, local.mocked.$count(“whatever”));


I didn’t know if there was a way to get Mockbox to spy on those methods without mocking them. I know you do some clever stuff where a proxy gets created and written to disk, so didn’t know if there was a way to leverage that to do a kind of AOP to record that the method was called.



Since they are integration tests you a nt wipe them. In ord to track them they must be wiped. I say try an AOP approach and maybe submit a new feature request where you can just track method calls. That could be a nifty little utility and easily implemented

Thanks Luis - I will log a feature request