如何将 SequenceRunner 与 FlexUnit 4 结合使用

发布于 2024-09-14 01:38:48 字数 1236 浏览 5 评论 0原文

FlexUnit wiki 中,我读到了非常有趣的 SequenceRunner由 Fluint 人员贡献。现在我尝试运行一个与示例非常相似的测试,但是在执行 SequenceRunner 实例的 run() 方法时,我收到此异常:

    Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async
Error: Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async
    at org.flexunit.async::AsyncLocator$/getCallableForTest()[C:\Users\dmoor e\Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\flexunit\async\AsyncLocator.as:82]
    at org.fluint.sequence::SequenceWaiter/setupListeners()[C:\Users\dmoore\ Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceWaiter.as:100]
    at org.fluint.sequence::SequenceRunner/continueSequence()[C:\Users\dmoor e\Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceRunner.as:177]
    at org.fluint.sequence::SequenceRunner/run()[C:\Users\dmoore\Documents\_ Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceRunner.as:124]

是否有人已将 SequenceRunner 与 FlexUnit 4 一起使用。 [Test(async)] 注释已存在。

In the FlexUnit wiki I've read about the very interesting SequenceRunner that was contributed by the Fluint folks. Now I am trying to run a test that is very similar to the example, however when executing the run() Method of the SequenceRunner instance, I get this exception:

    Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async
Error: Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async
    at org.flexunit.async::AsyncLocator$/getCallableForTest()[C:\Users\dmoor e\Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\flexunit\async\AsyncLocator.as:82]
    at org.fluint.sequence::SequenceWaiter/setupListeners()[C:\Users\dmoore\ Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceWaiter.as:100]
    at org.fluint.sequence::SequenceRunner/continueSequence()[C:\Users\dmoor e\Documents\_Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceRunner.as:177]
    at org.fluint.sequence::SequenceRunner/run()[C:\Users\dmoore\Documents\_ Production\Flex Unit 4\GIT\FlexUnit4\src\org\fluint\sequence\SequenceRunner.as:124]

Has anyone used the SequenceRunner with FlexUnit 4 already. The [Test(async)] annotation is already present.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

弥枳 2024-09-21 01:38:48

这是一个完整的、非常简单的示例测试用例类。

package test
{
    import flash.events.Event;

    import org.flexunit.asserts.assertEquals;

    import org.fluint.sequence.SequenceRunner;
    import org.fluint.sequence.SequenceWaiter;

    public class test_case
    {
        [Test(async)]
        public function test_function():void
        {
            var counter:Object = { count: 0}
            var sr:SequenceRunner = new SequenceRunner(this);
            sr.addStep(new SequenceWaiter(new TestWaiterTarget(counter), "myEvent", 50000));
            sr.addStep(new SequenceWaiter(new TestWaiterTarget(counter), "myEvent", 5000))
            sr.addAssertHandler(test_function_handler, counter);
            sr.run();
        }

        private function test_function_handler(event:Event, passthroughData:*):void
        {
            assertEquals(passthroughData.count, 2);
        }
    }
}

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.Timer;

class TestWaiterTarget extends EventDispatcher
{
    var timer:Timer = new Timer(250, 1);

    private var _counter:Object;

    public function TestWaiterTarget(counter)
    {
        _counter = counter;
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_timerCompleteHandler);
        timer.start();
    }

    private function timer_timerCompleteHandler(event:TimerEvent):void
    {
        _counter.count++;
        dispatchEvent(new Event("myEvent"));
    }
}

Here is a complete, very simple example test case class.

package test
{
    import flash.events.Event;

    import org.flexunit.asserts.assertEquals;

    import org.fluint.sequence.SequenceRunner;
    import org.fluint.sequence.SequenceWaiter;

    public class test_case
    {
        [Test(async)]
        public function test_function():void
        {
            var counter:Object = { count: 0}
            var sr:SequenceRunner = new SequenceRunner(this);
            sr.addStep(new SequenceWaiter(new TestWaiterTarget(counter), "myEvent", 50000));
            sr.addStep(new SequenceWaiter(new TestWaiterTarget(counter), "myEvent", 5000))
            sr.addAssertHandler(test_function_handler, counter);
            sr.run();
        }

        private function test_function_handler(event:Event, passthroughData:*):void
        {
            assertEquals(passthroughData.count, 2);
        }
    }
}

import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.TimerEvent;
import flash.utils.Timer;

class TestWaiterTarget extends EventDispatcher
{
    var timer:Timer = new Timer(250, 1);

    private var _counter:Object;

    public function TestWaiterTarget(counter)
    {
        _counter = counter;
        timer.addEventListener(TimerEvent.TIMER_COMPLETE, timer_timerCompleteHandler);
        timer.start();
    }

    private function timer_timerCompleteHandler(event:TimerEvent):void
    {
        _counter.count++;
        dispatchEvent(new Event("myEvent"));
    }
}
芸娘子的小脾气 2024-09-21 01:38:48

感谢 Michael Labriola 在 Adobe 论坛 中回答了我的问题,我终于能够使其运行。请注意,Wiki 中的 SequenceRunner 的文档是过时且部分错误。

  1. 不要从任何 TestCase 类继承。
  2. 在setUp中跳过CREATION_COMPLETE的asyncHandler。而是在测试中添加一个 SequenceWaiter 来等待组件的 CREATION_COMPLETE 事件
  3. 该测试必须标记为异步测试,因此添加 [Test(async) ] 使用 SequenceRunner 的测试用例的元数据。

Thanks to Michael Labriola, who responded to my question in the Adobe Forum I was finally able to make it running. Note that the documentation of SequenceRunner in the Wiki is outdated and partially wrong.

  1. Do not inherit from any TestCase class.
  2. Skip the asyncHandler for CREATION_COMPLETE in the setUp. Rather add a SequenceWaiter in the test that waits for the CREATION_COMPLETE event of the component
  3. The test must be marked as asynchronous test, so add the [Test(async)] Metadata to test cases that use SequenceRunner.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文