FlexUnit 和 callLater

发布于 2024-07-25 22:09:23 字数 748 浏览 2 评论 0原文

我尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

流年已逝 2024-08-01 22:09:23

首先,您确实应该考虑迁移到 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

盗心人 2024-08-01 22:09:23

看起来您正在期待一场活动,但却没有得到。 我想下面的代码会起作用。

public function testCallLater():void {
   Application.application.callLater( addAsync(function(/*removed event declaration*/):void {
      assertTrue(true);
   }, 1000));
}

It looks like you are expecting an event, but not getting one. I imagine the following code would work.

public function testCallLater():void {
   Application.application.callLater( addAsync(function(/*removed event declaration*/):void {
      assertTrue(true);
   }, 1000));
}
情场扛把子 2024-08-01 22:09:23

以防万一有人需要它,这有效:

private function testCallLater():void {
    Application.application.callLater(doCallLater, [ addAsync(funcUnderTest, 1000) ]);
}

private function doCallLater(testFunc:Function):void {
    testFunc(null);  // Dummy arg necessary because of addAsync expecting one arg
}

private function funcUnderTest(e:Object = null):void {
    assertTrue(true);
}

Just in case someone needs it, this works :

private function testCallLater():void {
    Application.application.callLater(doCallLater, [ addAsync(funcUnderTest, 1000) ]);
}

private function doCallLater(testFunc:Function):void {
    testFunc(null);  // Dummy arg necessary because of addAsync expecting one arg
}

private function funcUnderTest(e:Object = null):void {
    assertTrue(true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文