試圖讓我的頭腦模糊,在我的項目中實現一些單元測試。我想測試我的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」從哪裏來? –