试图让我的头脑模糊,在我的项目中实现一些单元测试。我想测试我的MainMediator,并且因为在我的MainMediator onRegister调用中创建了一些对象,所以我想我应该嘲笑这些对象。 希望这是正确的开始!asmock以前的方法需要返回值或抛出的异常
我有这样的事情
[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();
}
当我一步通过测试,并在mockRepository.stubEvents(调度员)停止。我可以在myService类 Error: Previous method IMyService/clientID/get(); requires a return value or an exception to throw
中看到错误。 clientID恰好是我的第一个属性,因此它被选中。
我以为要么StubOptions.NONE将意味着没有属性被残留或我的SetupResult.forCall(myService.clientID)会解决它,但没有。
回答这个问题的评论回复:在此事件,我有:
MyService extends ServiceBase implements IMyService
其中ServiceBase extends Actor
我发现我需要在IMyService下列以获得访问此事件。
function get eventDispatcher():IEventDispatcher;
function set eventDispatcher(dispatcher:IEventDispatcher):void;
不太确定这是否正确。现在有点困惑。
能有人告诉我我要去哪里错了吗? 谢谢!
“myService eventDispatcher”从哪里来? –