Selectively running tests

The org.flexunit.runner package comes with a static class named Request. Request is made specifically for selectively running tests or test cases. Here, we give three examples of how it can be used in the simplest context. In many cases, this functionality is used to integrate FlexUnit tests with some kind of custom UI, most likely for selecting and running tests.

In the auto-generated FlexUnitApplication.mxml file, there should be a function named currentRunTestSuite(). This function returns an array, and although it's exact specifications may differ depending on what UI and customer listeners are being used, it will always push the test suites, cases, or methods onto the testsToRun array, as shown:

public function currentRunTestSuite():Array
{
    ...

    var testsToRun:Array = new Array();
    testsToRun.push( SuiteToRun );
    return testsToRun;
}

If we desired to selectively run a single test method, we would modify the function as follows:

var testsToRun:Array = new Array();
testsToRun.push( Request.method( SelectiveCase, "selectiveTest" ) );
return testsToRun;

The test case class is specified as the first argument of and a string of the test name is specified as the second argument. The 'FlexUnit Results' tab will show the following:

selectiveRunOneTest.PNG

If we want to request multiple tests from the same case, it's as simple as passing in the name strings within an array to the Request.methods() function:

var testsToRun:Array = new Array();
testsToRun.push( Request.methods( SelectiveCase, ["selectiveTest", "anotherSelectiveTest" ] ) );
return testsToRun;

The 'FlexUnit Results' tab will show the following:

selectiveRunTwoTests.PNG

Finally, if we want to request multiple tests from the same case, and then others from additional cases, we can just push more requests onto the array.

var testsToRun:Array = new Array();
testsToRun.push( Request.methods( SelectiveCase, ["selectiveTest", "anotherSelectiveTest" ] ) );
testsToRun.push( Request.method( AnotherSelectiveCase, "selectiveTest" ) );
return testsToRun;

The 'FlexUnit Results' tab will show the following:

selectiveRunThreeTests.PNG