Let's start from the top, [RunWith("org.flexunit.runners.Parameterized")] is needed to declare the runner for FlexUnit. If this is the first time that this runner is being invoked then you must declare a variable of type Parameterized as on line 3.<br>

Specifying [Parameters] is what will be passed into the constructor, these data sets can be used as dataProviders as well.<br>

<br>The first test, timesTwoTest, assigns its dataProvider of dataTwo array with the set values of [ 5, 10 ] [ 6, 12 ] [ 7, 14 ]. Now unlike theories, a separate test will be created for each data set naming it inside of Flexunit like so [nameOfTest][arg1][arg2][constructorArg1][constructor[Arg2]. For example the first test that you might see in your list would look something like this timesTwoTest_5_10_0_0<br>

<br>The doubleTest will run a total of nine times. It will run through all the data sets in the provider for each data set passed to the constructor.<br>

<br>If a test doesn't take any parameters, the test will only be ran for each data set that is passed to the constructor. For example the test doubleTest will only be ran three times. However if the test requires parameters and no dataProvider is provided, then an initialization error will be thrown.<br>
<br>

[1]  [RunWith("org.flexunit.runners.Parameterized")]
[2]  public class TestParameterized {
[3]      private var foo:Parameterized;
[4] 
[5]      [Parameters]
[6]      public static function data1():Array {
[7]          return [ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ];
[8]      }
[9] 
[10]     public static function dataTwo():Array {
[12]         return [ [ 5, 10 ], [ 6, 12 ], [ 7, 14 ] ];
[13]     }
[14] 
[15]     public static function dataThree():Array {
[16]         return [ [ 0, 0 ], [ 1, 3 ], [ 2, 6 ] ];
[17]     }
[18] 		
[19]     [Test(dataProvider="dataTwo")]
[20]     public function timesTwoTest( value:int, required:int ):void {
[21]         Assert.assertEquals( 2*value, required );
[22]     }
[23] 
[24]     [Test(dataProvider="dataThree")]
[25]     public function timesThreeTest( value:int, required:int ):void {
[26] 	     Assert.assertEquals( 3*value, required );
[27]     }
[28] 
[29]     [Test]
[30]     public function doubleTest():void {
[31]         Assert.assertEquals(_expected, _input*2);
[32]     }
[33] 
[34]     private var _input:int;
[35]     private var _expected:int;
[36] 		
[37]     public function TestParameterized( param1:int, param2:int ) {
[38]         _input = param1;
[39]         _expected = param2;
[40]     }	
[41] }
  • No labels