- Import package import org.flexunit.runners.Parameterized;.
- Add the meta data [RunWith("org.flexunit.runners.Parameterized")] at the top of the parameterized test class.
- Declare a static data set(i.e. myTestData).
- Add the meta data [Test(dataProvider="myTestData")] at the top of the test function. Make sure that the order of the function parameters(i.e. iA:int, iB:int, iExpected:int) match the order your data set.
package org.tutorial.calculator.unittest
{
import org.flexunit.runners.Parameterized;
import org.flexunit.asserts.assertEquals;
[RunWith("org.flexunit.runners.Parameterized")]
public class FlexParameterizedTest
{
public static var myTestData:Array = [
// iA, iB, iExpected
[2, 4, 6],
[-2,4, 2],
[5, 6, 14], // Will fail.
[0, 1, 1],
];
[Test(dataProvider="myTestData")]
public function getSumTest(iA:int, iB:int, iExpected:int): void
{
assertEquals("getSum() doesn't give expected result.", iExpected, this.getSum(iA, iB));
}
/**
* Function to be tested. It adds 2 integers.
* Note: For convenient and completeness, I put this function
* in this same test class. In practice, you shouldn't.
*/
public function getSum(iA:int, iB:int): int
{
return iA+iB;
}
}
}