Question

If you create a pure ActionScript project in Flex Builder 3 and want to do unit testing using flexunit, what is the best option?

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.

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. 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. 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.
Was it helpful?

Solution

There's always ASUnit.

OTHER TIPS

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.

We've done something similar in order to get FlexUnit working with CruiseControl.net (continuous integration server).

In our implementation, we have the code below run in the FlexEvent.CREATION_COMPLETE handler of the Application class.

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).

// 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 {}

Maybe you could use flexunit.textui.TestRunner, which output the result to the Console.

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.

Try AS3Unit from libspark. They also have an async beta test kit.

Try AS3Unit from libspark. They also have an async beta test kit.

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.

You can check out how we've set up the build for Robotlegs using FlexUnit4 and their CI ant tasks.

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.

It has been very effective and easy to use across many contributors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top