从命令行构建并运行 FlexUnit

发布于 2024-09-15 12:41:36 字数 579 浏览 1 评论 0原文

我正在使用 ActionScript3 和 Flash Builder 4 作为我的 IDE 构建一个应用程序。

IDE 支持称为“FlexUnit”的单元测试框架。

我可以在 IDE 中构建并运行测试,没问题。

经过很多痛苦和磨难后,我弄清楚了如何从命令行将单元测试构建为 swf。我可以将浏览器或 Flash 播放器指向 swf 并运行测试。

但对于自动化构建系统来说,这并不好:我想构建测试,运行它们,并收集/分析结果以判断哪些测试(如果有)失败。

我可以想象一些黑客行为:破解 FlexUnit 基础库以将输出转储到 stderr 而不仅仅是 IDE 控制台。一起破解一些脚本,将浏览器指向 swf,数到 60,终止浏览器并检查 stderr。

但这太可怕了。

我必须相信有某种从命令行构建和运行的方法可以很好地与自动构建系统配合使用。

更复杂的是:我对 ActionScript 是一个相对菜鸟(大约 1 个月)。我的背景是 C++、makefile 等。我必须做的所有事情,甚至是在 ide 之外构建的测试(build.xml 文件,ant)对我来说都是完全希腊语,只需从我能找到的示例中剪切粘贴即可。

I am building an app using ActionScript3 with Flash Builder 4 as my IDE.

The IDE supports a unit testing framework called "FlexUnit".

I can build and run tests within the IDE, no problem.

After much pain and suffering I figured out how to build the unit tests as a swf from the command line. I can point a browser or flash player at the swf and the tests run.

But for an automated build system this is no good: I would like to build the tests, run them, and collect/analyze the results to tell which tests, if any, are failing.

I can imaging some hackery: hack FlexUnit base libraries to dump output to stderr instead of just to the IDE console. Hack some script together that points a browser at the swf, counts to 60, kills the browser and checks stderr.

But that's hideous.

I have to believe there's some way to build and run from the command line that works nicely with automated build systems.

Further complication: I am a relative noob with ActionScript (~1 month). My background is C++, makefiles, etc. All the stuff I had to do to get the tests even to build outside the ide (a build.xml file, ant) was complete greek to me, just cut n pasting from examples I could find.

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

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

发布评论

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

评论(2

Hello爱情风 2024-09-22 12:41:36

据我所知,运行 swf 的唯一选择是在浏览器或独立播放器中。只要您可以获得测试结果并退出应用程序,在播放器中运行对于您的持续集成环境来说应该不是问题。

要将测试结果打印到标准输出,您需要向 testunit 核心实例添加一个文本侦听器。

core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );

要在测试运行后退出应用程序...

System.exit(0);

例如,您的顶级 mxml 文件可能如下所示...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    creationComplete="runMe()" 
    xmlns:adobe="http://www.adobe.com/2009/flexUnitUIRunner"
    >
    <mx:Script>
        <![CDATA[
            import org.flexunit.runner.FlexUnitCore;
            //import org.flexunit.listeners.UIListener;
            //import org.flexunit.listeners.CIListener;
            import org.flexunit.internals.TextListener;
            import mx.logging.LogEventLevel;
            import flash.system.System
            import unit_tests.TestAuthentication.TestAuthentication

            private var core:FlexUnitCore;

            public function runMe():void {
                core = new FlexUnitCore();
                //core.addListener(new UIListener(uiListener));
                //core.addListener(new CIListener());
                core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );
                core.run( TestAuthentication );
                System.exit(0);
            }
        ]]>
    </mx:Script>
</mx:Application>

然后您需要做的就是解析输出。
它不像我们希望的那么优雅,但它应该可以工作。

As far as I'm aware your only options for running the swf are in the browser or in the standalone player. Running in the player should not be a problem for your continuous integration environment as long as you can get at the test results and exit the application.

To print test results to stdout you need to add a Text listener to your testunit core instance.

core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );

To exit the application after the tests have run...

System.exit(0);

For example, your top level mxml file might look like this...

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    creationComplete="runMe()" 
    xmlns:adobe="http://www.adobe.com/2009/flexUnitUIRunner"
    >
    <mx:Script>
        <![CDATA[
            import org.flexunit.runner.FlexUnitCore;
            //import org.flexunit.listeners.UIListener;
            //import org.flexunit.listeners.CIListener;
            import org.flexunit.internals.TextListener;
            import mx.logging.LogEventLevel;
            import flash.system.System
            import unit_tests.TestAuthentication.TestAuthentication

            private var core:FlexUnitCore;

            public function runMe():void {
                core = new FlexUnitCore();
                //core.addListener(new UIListener(uiListener));
                //core.addListener(new CIListener());
                core.addListener( TextListener.getDefaultTextListener( LogEventLevel.DEBUG ) );
                core.run( TestAuthentication );
                System.exit(0);
            }
        ]]>
    </mx:Script>
</mx:Application>

Then all you need to do is parse the output.
It's not as elegant as we might like but it should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文