flex - asmock Previous method requires a return value or an exception to throw -
trying head around asmock implement unit testing in project. want test mainmediator , since there objects created in mainmediator onregister call, i'm thinking should mock objects. that's correct begin with!
i have this
[rule] public var includemocks : includemocksrule = new includemocksrule([ ieventdispatcher, imyservice ]); [before] public function setup():void { mockrepository = new mockrepository(); mainview = new mainview(); mainmediator = new mainmediator(); dispatcher = ieventdispatcher(mockrepository.createstub(ieventdispatcher, stuboptions.none)); myservice = imyservice(mockrepository.createstub(imyservice, stuboptions.none)); mockrepository.stubevents(dispatcher); setupresult.forcall(chatservice.clientid) .returnvalue(""); mockrepository.replayall(); mainmediator.eventdispatcher = dispatcher; myservice.eventdispatcher = dispatcher; mainmediator.service = myservice; .... mainmediator.onregister(); }
when step through test , stop @ mockrepository.stubevents(dispatcher). can see errors in myservice class error: previous method imyservice/clientid/get(); requires return value or exception throw
. clientid happens first property hence why it's being picked on.
i thought either stuboptions.none mean no properties stubbed or setupresult.forcall(myservice.clientid) fix none did.
answering question in comment re: eventdispatcher, have:
myservice extends servicebase implements imyservice
where servicebase extends actor
i found need following in imyservice access eventdispatcher.
function eventdispatcher():ieventdispatcher; function set eventdispatcher(dispatcher:ieventdispatcher):void;
not sure if correct. bit confused now.
can please tell me i'm going wrong? thanks!
this common problem when mocking concrete classes, rather interfaces: if constructor calls method (or property getter), return null because hasn't been mocked yet.
there's not anyway workaround it, except abstract class through interface , mock that.
Comments
Post a Comment