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