为了让 FlexUnit 与 CruiseControl.net(持续集成服务器)一起工作,我们做了类似的事情。
在我们的实现中,我们在 Application 类的 FlexEvent.CREATION_COMPLETE 处理程序中运行以下代码。
如何输出单元测试的结果完全取决于您。我们的实现已与 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 {}