无法让 ASMock 发送事件
我找不到我的错误,希望有人能帮助我。 我正在尝试使用 ASMock 对我的 ActionScript 应用程序进行单元测试。 我想执行异步测试,但我没有调度我的模拟函数。 这就是我所做的:
[Test(async,timeout="5000")]
public function testFailedIDResponse() : void {
var mockRepository : MockRepository = new MockRepository();
// Record
var oMock:ConnectionProcessor = ConnectionProcessor(mockRepository.createStub(ConnectionProcessor));
oMock.addEventListener("ConnectionProcessor.LOGICALERROR", Async.asyncHandler(this, onWrongID, 5000));
SetupResult.forCall(oMock.logigalErrorCode).returnValue("NOT_FOUND");
SetupResult.forEventDispatcher(oMock);
SetupResult.forCall(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
mockRepository.replayAll();
oMock.load();
但事件永远不会到达我的 onWrongID 处理程序。 我的错误在哪里? 非常感谢大家!
I can't find my mistake, hope someone can help me out.
I am trying to unit test my actionscript application using ASMock.
I want to perform an asynchron test, but I don't get my mocked function to dispatch.
this is what I did:
[Test(async,timeout="5000")]
public function testFailedIDResponse() : void {
var mockRepository : MockRepository = new MockRepository();
// Record
var oMock:ConnectionProcessor = ConnectionProcessor(mockRepository.createStub(ConnectionProcessor));
oMock.addEventListener("ConnectionProcessor.LOGICALERROR", Async.asyncHandler(this, onWrongID, 5000));
SetupResult.forCall(oMock.logigalErrorCode).returnValue("NOT_FOUND");
SetupResult.forEventDispatcher(oMock);
SetupResult.forCall(oMock.load()).dispatchEvent(new Event("ConnectionProcessor.LOGICALERROR"));
mockRepository.replayAll();
oMock.load();
but the event never arrives at my onWrongID handler.
where is my error?
thanks a lot guys!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将调用移至
addEventListener
,直到replayAll
之后。就目前情况而言,它只是记录您对addEventListener
的调用。You need to move your call to
addEventListener
until afterreplayAll
. As it stands, it's just recording your call toaddEventListener
.您只需从模拟对象中调用dispatchEvent-方法即可。
例如
,那么您的测试类/方法/...将能够处理该事件。
或者,如果您希望在可以工作之前在某个地方调用 load 方法,
希望有所帮助。
br,
You just have to call the dispatchEvent-method from your mocked object.
e.g.
Then your class/method/... under test will be able to handle the event.
or if you expect the load method to be called in somewhere before you could work with
hope that helped.
br,