FlexUnit 和 callLater
我尝试将 callLater 与 FlexUnit v0.9 一起使用:
public function testCallLater():void {
Application.application.callLater( addAsync(function():void {
assertTrue(true);
}, 1000));
}
但是当它运行时,我收到此错误:
ArgumentError: Error #1063: Argument count mismatch on flexunit.framework::AsyncTestHelper/handleEvent(). Expected 1, got 0.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
我不确定问题是什么。 callLater 与 FlexUnit 不兼容吗?
I'm trying to use callLater with FlexUnit v0.9:
public function testCallLater():void {
Application.application.callLater( addAsync(function():void {
assertTrue(true);
}, 1000));
}
but when it runs I get this error:
ArgumentError: Error #1063: Argument count mismatch on flexunit.framework::AsyncTestHelper/handleEvent(). Expected 1, got 0.
at Function/http://adobe.com/AS3/2006/builtin::apply()
at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8628]
at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\core\UIComponent.as:8568]
I'm not sure what the problem is. Is callLater incompatible with FlexUnit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您确实应该考虑迁移到 FlexUnit 4.0: http://blogs.digitalprimates.net/codeSlinger/index.cfm/2009/5/3/FlexUnit-4-in-360-seconds
其次,callLater是用来延迟的处理直到视觉类中的下一帧。 您的测试用例类不是扩展 UIComponent 的可视类,因此您不应尝试使用 callLater。
第三,addAsync用于测试异步操作的结果。 这通常用于测试网络请求、文件读取、计时器事件等的结果。这就是为什么通常您会在 addAsync 测试函数中看到“事件”作为参数(因为异步请求使用事件来过程结果)。 在您的情况下,您没有通过 addAsync 调用响应异步操作,因此您不应该在测试函数中查找事件。 删除 event:Event 参数,错误就会消失。
但是,也许您可以重新表述这个问题来说明您想要实现的目标? 您指出的代码示例并没有真正做任何有用的事情。 如果您能更具体一点,我们可以帮助您编写更好的测试用例。
有关在旧版本 FlexUnit 中使用 addAsync 的帮助,请参阅本教程:http:/ /life.neophi.com/danielr/2007/03/asynchronous_testing_with_flex.html
First, you should really consider migrating to FlexUnit 4.0: http://blogs.digitalprimates.net/codeSlinger/index.cfm/2009/5/3/FlexUnit-4-in-360-seconds
Second, callLater is meant to be used to delay processing until the next frame in visual classes. Your test case class is not a visual class extending UIComponent, therefore you should not try to use callLater.
Third, addAsync is use to test the results of an asynchronous operation. This is typically used in testing the results of a network request, of a file read, of a timer event, etc. That is why normally you see an "event" as a parameter in the addAsync test function (because asynchronous requests use events to process results). In your case, you're not responding to an asynchronous operation with your addAsync call, and therefore you shouldn't be looking for an event in your test function. Remove the event:Event parameter and the error will go away.
However, perhaps you can re-phrase this question to state what you're trying to accomplish? The code sample that you've indicated is not really doing anything useful. If you can be a little more specific we can help you write a better test case.
For help with using addAsync with older versions of FlexUnit, see this tutorial: http://life.neophi.com/danielr/2007/03/asynchronous_testing_with_flex.html
看起来您正在期待一场活动,但却没有得到。 我想下面的代码会起作用。
It looks like you are expecting an event, but not getting one. I imagine the following code would work.
以防万一有人需要它,这有效:
Just in case someone needs it, this works :