Uniting Testing Handlers, Mock Controllers and Setting Properties

Hello Guys,

Back into my adventures of unit testing today. On my agenda this morning is unit tests for handlers, and I’m running into a few snags.

Fistly, I’m trying to mock some properties of the controller, which would usually be injected, things like settings and services.

public void function setUp() {

// Call the super setup method to setup the app.

super.setup();

// We need to mock the service.

serviceService = getMockBox().createStub();

// Mock the methods for find all, by default this will return null.

serviceService.$(“findWhere”);

// Place this service as a property into the handler.

getController().$property(propertyName=“ServiceService”, mock=serviceService);

}

I’ve tried to set these in my setup method like so, but they seem to just fail with an exception that says the mock controller has no method $property.

Can anyone offer any more advice on how to set these properties? am I even approaching the unit test of the handler correctly? or should I be extending BaseHandlerTest.cfc?

Thanks,

Robert

I don't know for sure, but I guess the mocked object is decorated with
the $property method, so you won't be able to use it on the controller
if it's not mocked.

Hi John,

It would seem so, looks as if the mockController isn’t actually a mock. :-s

I’m just experimenting with ideas trying to find a clean way to unit test handler methods, but not really able to get anything running at the moment.

Robert