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). It is impossible to add the mxml file to the "ActionScript Applications" list in the project settings.
内置的Flex构建器将拒绝构建包含TestRunnerBase组件的mxml文件,因为它是纯ActionScript项目(不允许Flex)。无法将mxml文件添加到项目设置中的“ActionScript Applications”列表中。
Right now I can see two options, both undesirable.
现在我可以看到两个选项,都是不可取的。
- Add the unit testing mxml file to the project and create an external tool setup to build and run it. This is the approach I'm taking now, and it works fine, except that interactive debugging is impossible.
- 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. 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文件添加到项目中,并创建外部工具设置以构建和运行它。这是我现在采用的方法,它工作正常,除了交互式调试是不可能的。
为测试mxml文件创建一个新的Flex项目,并将主项目的src目录添加为构建选项中的附加源目录。我不喜欢这种方法,因为除了维护两个项目的丑陋之外,它还要求我将mxml文件保存在与所有其他源文件不同的目录树中。
9 个解决方案
#2
1
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. This setup seems to work fine.
我最终将单元测试mxml文件放在原始项目中,创建一个新的Flex项目,删除src目录,并将其替换为Eclipse链接文件夹到ActionScript项目的src目录。这个设置似乎工作正常。
#3
1
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 {}
#4
1
Maybe you could use flexunit.textui.TestRunner, which output the result to the Console.
也许你可以使用flexunit.textui.TestRunner,它将结果输出到Console。
#5
1
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项目,它取决于被测项目。
#6
1
Try AS3Unit from libspark. They also have an async beta test kit.
从libspark尝试AS3Unit。他们还有一个异步beta测试工具包。
#7
0
Try AS3Unit from libspark. They also have an async beta test kit.
从libspark尝试AS3Unit。他们还有一个异步beta测试工具包。
#8
0
remove the 'excludedEntries' element in your project's .actionScriptProperties file should work, I use this way to build mxml file in my pure actionscript project.
删除项目的.actionScriptProperties文件中的'excludedEntries'元素应该工作,我用这种方式在我的纯actionscript项目中构建mxml文件。
#9
0
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. src and test folders are both set up as src paths. 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.
对于版本控制,我们删除所有Flex / Flash Builder项目文件。 src和test文件夹都设置为src路径。通过ant build进行测试。或者,如果你是视觉测试跑步者,可以设置第二个带跑步者的项目。
It has been very effective and easy to use across many contributors.
它在许多贡献者中非常有效且易于使用。
#1
#2
1
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. This setup seems to work fine.
我最终将单元测试mxml文件放在原始项目中,创建一个新的Flex项目,删除src目录,并将其替换为Eclipse链接文件夹到ActionScript项目的src目录。这个设置似乎工作正常。
#3
1
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 {}
#4
1
Maybe you could use flexunit.textui.TestRunner, which output the result to the Console.
也许你可以使用flexunit.textui.TestRunner,它将结果输出到Console。
#5
1
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项目,它取决于被测项目。
#6
1
Try AS3Unit from libspark. They also have an async beta test kit.
从libspark尝试AS3Unit。他们还有一个异步beta测试工具包。
#7
0
Try AS3Unit from libspark. They also have an async beta test kit.
从libspark尝试AS3Unit。他们还有一个异步beta测试工具包。
#8
0
remove the 'excludedEntries' element in your project's .actionScriptProperties file should work, I use this way to build mxml file in my pure actionscript project.
删除项目的.actionScriptProperties文件中的'excludedEntries'元素应该工作,我用这种方式在我的纯actionscript项目中构建mxml文件。
#9
0
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. src and test folders are both set up as src paths. 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.
对于版本控制,我们删除所有Flex / Flash Builder项目文件。 src和test文件夹都设置为src路径。通过ant build进行测试。或者,如果你是视觉测试跑步者,可以设置第二个带跑步者的项目。
It has been very effective and easy to use across many contributors.
它在许多贡献者中非常有效且易于使用。