简体   繁体   English

flexunit与Flex Builder 3中的纯ActionScript项目

[英]flexunit with pure ActionScript project in Flex Builder 3

If you create a pure ActionScript project in Flex Builder 3 and want to do unit testing using flexunit, what is the best option? 如果您在Flex Builder 3中创建纯ActionScript项目并希望使用flexunit进行单元测试,那么最佳选择是什么?

The built-in Flex builder will refuse to build the mxml file containing the TestRunnerBase component as it is a pure ActionScript project (no Flex allowed). 内置的Flex构建器将拒绝构建包含TestRunnerBase组件的mxml文件,因为它是一个纯ActionScript项目(不允许Flex)。 It is impossible to add the mxml file to the "ActionScript Applications" list in the project settings. 无法将mxml文件添加到项目设置中的“ActionScript Applications”列表中。

Right now I can see two options, both undesirable. 现在我可以看到两个选项,都是不受欢迎的。

  1. Add the unit testing mxml file to the project and create an external tool setup to build and run it. 将单元测试mxml文件添加到项目中,并创建一个外部工具设置来构建和运行它。 This is the approach I'm taking now, and it works fine, except that interactive debugging is impossible. 这是我现在采用的方法,它工作正常,除了交互式调试是不可能的。
  2. Create a new Flex project just for the test mxml file and add the main project's src directory as an additional source directory in the build options. 为测试mxml文件创建一个新的Flex项目,并将主项目的src目录添加为构建选项中的附加源目录。 I don't like this approach because it requires that I keep the mxml file in a separate directory tree from all the other source files in addition to the ugliness of maintaining two projects. 我不喜欢这种方法,因为除了维护两个项目的丑陋之外,它还要求我将mxml文件保存在与所有其他源文件不同的目录树中。

总有ASUnit

I ended up putting the unit test mxml file in the original project, creating a new Flex project, deleting the src directory, and replacing it with an Eclipse linked folder to the src directory of the ActionScript project. 我最终将单元测试mxml文件放在原始项目中,创建一个新的Flex项目,删除src目录,并将其替换为Eclipse链接文件夹到ActionScript项目的src目录。 This setup seems to work fine. 这个设置似乎工作正常。

We've done something similar in order to get FlexUnit working with CruiseControl.net (continuous integration server). 我们已经做了类似的事情,以使FlexUnit与CruiseControl.net(持续集成服务器)一起工作。

In our implementation, we have the code below run in the FlexEvent.CREATION_COMPLETE handler of the Application class. 在我们的实现中,我们在Application类的FlexEvent.CREATION_COMPLETE处理程序中运行以下代码。

How you output the results of the unit tests is completely up to you. 如何输出单元测试的结果完全取决于您。 Our implementation has been used with both AIR and Zinc3 and both output an NUnit-friendly XML representation and then exit the application (with an exit code of -1 if any tests failed). 我们的实现已经与AIR和Zinc3一起使用,并且都输出NUnit友好的XML表示,然后退出应用程序(如果任何测试失败,退出代码为-1)。

// import mx.core.Application;
// import flexunit.framework.*;

// class AutomatedTestHarness extends Application implements TestListener

private function creationCompleteHandler(event : Event) : void
{
    this._result = new TestResult();
    this._result.addListener(this);

    var testSuite : TestSuite = new TestSuite();
    this.addUnitTests(testSuite);

    testSuite.runWithResult(_result);
}

/**
  * Implement these as part of TestResult.addListener
  * If you want to output xml after the tests run, do so here
  * (Tip: Count tests in endTest and compare the count to testSuite.countTestCases()
  * to find out when all tests have completed)
  */
function startTest(test : Test) : void {}
function endTest(test : Test) : void {}
function addError(test : Test, error : Error) : void {}
function addFailure(test : Test, error : AssertionFailedError) : void {}

也许您可以使用flexunit.textui.TestRunner,它将结果输出到控制台。

We've factored out all the code we want to test into library projects. 我们已经将我们想要测试的所有代码考虑到库项目中。 We then just have a separate project for our tests, which is a flex project, which depends on the project under test. 然后我们为测试提供了一个单独的项目,这是一个flex项目,它取决于被测项目。

Try AS3Unit from libspark. 从libspark尝试AS3Unit They also have an async beta test kit. 他们还有一个异步beta测试工具包。

删除项目的.actionScriptProperties文件中的'excludedEntries'元素应该工作,我用这种方式在我的纯actionscript项目中构建mxml文件。

You can check out how we've set up the build for Robotlegs using FlexUnit4 and their CI ant tasks. 您可以查看我们如何使用FlexUnit4及其CI ant任务为Robotlegs设置构建

For version control we strip out all of the Flex/Flash Builder project files. 对于版本控制,我们删除所有Flex / Flash Builder项目文件。 src and test folders are both set up as src paths. src和test文件夹都设置为src路径。 Tests are rand via the ant build. 通过蚂蚁构建进行测试。 Alternatively a second project with a runner can be set up if you life the visual test runner. 或者,如果你是视觉测试跑步者,可以设置第二个带跑步者的项目。

It has been very effective and easy to use across many contributors. 它在许多贡献者中非常有效且易于使用。

Try AS3Unit from libspark. 从libspark尝试AS3Unit。 They also have an async beta test kit. 他们还有一个异步beta测试工具包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM