Flash Builder 4.5 &弹性单元4.1

发布于 2024-11-26 16:47:34 字数 741 浏览 2 评论 0原文

我们正在使用 Flex 4.1 编写一个大型的多模块产品,该产品运行在基于 Java 的中间层之上。

我有 Java 背景,希望在 Flex 环境中获得编写和运行单元测试的支持。

我已经使用 FlexUnit 4.1 版本更新了 Flash Builder 4.5,并且可以在应用程序项目上成功编写和执行单元测试,但我还没有弄清楚如何在 Flash Builder 中对模块或库项目进行单元测试。

库项目的问题

由于我们需要将测试编译到应用程序 (SWF),因此我需要在 Flash Builder 中创建一个配套项目,或者更改库 (SWC) 项目依赖项上的链接类型以避免外部,因为外部依赖项预计由其他人(通常是顶级应用程序)提供。

作为实验,我尝试更改示例库项目上的链接:成功生成了测试运行程序 SWF,但 FlexUnit 无法运行它,因为报告了对我来说没有任何意义的内容 #1065 错误。

对于我们的无头构建(使用 Gradle),我发现只需在生成测试运行程序 SWF 时合并所有依赖项(无论其原始链接如何)即可轻松解决此问题。我还可以使用外部工具支持从 Eclipse 中轻松运行此程序,因为结果是与 JUnit 兼容的 XML 结果,并显示在通常的 JUnit 视图中。

你是如何做到的?

其他 Flex 开发人员如何在多模块和多库项目中构建他们的单元测试?您是否在 Flash Builder 4.5 中运行测试?您可以为任何库或模块项目独立运行测试吗?

We have a large, multi-module product we are writing in Flex 4.1 running on top of a Java-based middle-tier.

Coming from a Java background, I want to have support in our Flex environment for writing and running unit tests.

I've updated Flash Builder 4.5 with the 4.1 release of FlexUnit and I can write and execute unit tests successfully on an application project, but I haven't worked out how to get unit tests working on module or library projects within Flash Builder.

Problems with Library Projects

Since we need the tests compiled to an application (SWF), I either need to create a companion project in Flash Builder or change the linkage type on the library (SWC) project's dependencies to avoid external, since external dependencies are expected to made available by someone else (usually the top-level application).

As an experiment I tried changing the linkage on a sample library project: a test runner SWF was successfully generated, but FlexUnit failed to run it as a #1065 error was reported on something that didn't make any sense to me.

For our headless build (using Gradle), I found this easy to solve by simply merging all dependencies irrespective of their original linkage when generating the test runner SWF. I can also run this easily from within Eclipse using the external tool support as the results are JUnit-compatible XML results that display in the usual JUnit view.

How do you do it?

How do other Flex developers structure their unit tests in a multi-module and multi-library project? Do you run the tests from within Flash Builder 4.5? Can you run tests independently for any library or module project?

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

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

发布评论

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

评论(1

沧笙踏歌 2024-12-03 16:47:34

好的,这是我第二次回答自己的问题(上一次也是围绕 Flex)。

我已经为每个单独的项目添加了测试,但我从一个中央测试项目运行测试。

每个项目应该有:

  • 一个测试目录
  • 一个 MLXML 应用程序,测试目录中的命名约定为 Test.mxml
  • 一个顶级测试套件,聚合了测试下项目中的所有测试常见包结构中的目录
  • 一些单元测试;-)

Flash Builder 不喜欢 MXML 应用程序位于 src 之外的任何其他目录中,因此不要设置test 目录作为另一个源目录。

现在将每个项目的 test 源目录添加到整个测试项目中。您需要将所需的所有依赖项(运行时和测试)添加到该项目中。

我发现 FlexUnit 在管理单元测试的运行程序方面有点奇怪。当您选择“运行为 -> ”时,它将生成一个测试运行器 MXML 应用程序。 Eclipse 中的 Flex 单元测试(您可以选择它应该运行哪些测试)。从上下文菜单中选择“执行 FlexUnit 测试”不会导致 MXML 生成。

您不应将此 MXML 文件签入源代码管理,而应忽略它。原因是如果您想运行一组不同的测试,FlexUnit 不会成功重新生成该文件。这意味着您需要在想要重新生成文件时手动删除该文件。

以下是我们在库项目中用于测试运行程序的 MXML 示例:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           minWidth="955" minHeight="600" creationComplete="onCreationComplete()">

<fx:Script>
    <![CDATA[
        import net.infonic.hs.AllTestsSuite;

        import org.flexunit.listeners.CIListener;
        import org.flexunit.runner.FlexUnitCore;

        private var core: FlexUnitCore;

        public function currentRunTestSuite(): Array {
            var testsToRun:Array = new Array();
            testsToRun.push(AllTestsSuite);
            return testsToRun;
        }           

        private function onCreationComplete(): void {
            core = new FlexUnitCore();
            core.addListener(new CIListener());
            core.run(currentRunTestSuite());
        }           
    ]]>
</fx:Script>

</s:Application>

OK, this is the 2nd time I've answered my own question (the last one was also around Flex).

I've went for adding tests to each individual project, but I run the tests from a central test project.

Each project should have:

  • a test directory
  • a MLXML application with the naming convention of <project name>Test.mxml in the test directory
  • a top-level test suite aggregating all tests in the project under the test directory in the usual package structure
  • some unit tests ;-)

Flash Builder doesn't like MXML applications living in any other directory than src, so it's important to NOT set the test directory as another source directory.

Now add the test source directories from each project to the overall testing project. You'll need to add all dependencies needed (both runtime and test) to this project.

I find FlexUnit a bit weird in how it manages the runner for the unit tests. It will offer to generate a test runner MXML application when you select 'run as -> Flex Unit Tests' in Eclipse (you can choose which tests it should run). Selecting the 'Execute FlexUnit Tests' from the context menu doesn't cause the MXML generation.

You shouldn't check this MXML file into source control, but ignore it. The reason is that FlexUnit doesn't regenerate this file successfully if you want to run a different set of tests. This means you need to manually delete the file whenever you want to re-generate it.

Here's an example of the MXML we use for the test runner in a library project:

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/mx"
           minWidth="955" minHeight="600" creationComplete="onCreationComplete()">

<fx:Script>
    <![CDATA[
        import net.infonic.hs.AllTestsSuite;

        import org.flexunit.listeners.CIListener;
        import org.flexunit.runner.FlexUnitCore;

        private var core: FlexUnitCore;

        public function currentRunTestSuite(): Array {
            var testsToRun:Array = new Array();
            testsToRun.push(AllTestsSuite);
            return testsToRun;
        }           

        private function onCreationComplete(): void {
            core = new FlexUnitCore();
            core.addListener(new CIListener());
            core.run(currentRunTestSuite());
        }           
    ]]>
</fx:Script>

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