Question

I am trying to run a parametrized tests... Was trying to implement it like it explained here: http://docs.flexunit.org/index.php?title=Parameterized_Test_Styles

Here is what my test case looking

import org.flexunit.runners.Parameterized;

[RunWith("org.flexunit.runners.Parameterized")]
public class ArrayBasedStackTests
{       
    [Paremeters]
    public static var stackProvider:Array = [new ArrayBasedStack(), new LinkedListBasedStack()] ;

    private var _stack:IStack;

    public function ArrayBasedStackTests(param:IStack)
    {
        _stack = param;
    }


    [Before]
    public function setUp():void
    {
    }

    [After]
    public function tearDown():void
    {
    }

    [Test ( description = "Checks isEmpty method of the stack. For empty stack", dataProvider="stackProvider" )]
    public function isEmptyStackPositiveTest():void
    {
        var stack:IStack = _stack;
        assertEquals( true, stack.isEmpty() );
    }

But this code throws following initializing Error:

Error: Custom runner class org.flexunit.runners.Parameterized should be linked into project and implement IRunner. Further it needs to have a constructor which either just accepts the class, or the class and a builder.

Need help to fix it

UPDATE

I've updated the code so it looks like this

    [RunWith("org.flexunit.runners.Parameterized")]
public class ArrayBasedStackTests
{       
    private var foo:Parameterized;

    [Parameters]
    public static function stacks():Array
    {
        return  [ [new ArrayBasedStack()], [new LinkedListBasedStack()] ] ;
    }

    [Before]
    public function setUp():void
    {
    }

    [After]
    public function tearDown():void
    {
    }

    [Test ( description = "Checks isEmpty method of the stack. For empty stack", dataProvider="stacks")]
    public function isEmptyStackPositiveTest(stack:IStack):void
    {
        assertEquals( true, _stack.isEmpty() );
    }

It works. But the result is a bit strange. I have 4 test executed instead of 2. (I have 2 items in data provider, so cant get why do I have 4 tests).

Output

http://screencast.com/t/G8DHbcjDUkJ

Was it helpful?

Solution

The [Parameters] meta-data specifies that the parameters are passed to the constructor of the test - so the test class is called for each parameter. You also have the dataProvider set for the specific test method, so the test method is also called once for each parameter. Two calls for the test, and two calls to the method, ends up running four tests.

The solution is to either use [Parameters] meta-tag which specifies the data to use for the whole test class, or use the dataProvider for each test method, but not both with the same data at the same time.

OTHER TIPS

You're missing the static reference to Paramaterized, as shown here:

    import org.flexunit.runners.Parameterized;

[RunWith("org.flexunit.runners.Parameterized")]
public class MyTestNGTest
{       

    private var foo:Parameterized;
    ...

Basically, that error means that the [Runner] defined isn't available at runtime, which occurs if there is no static reference in the class to cause it to get linked in.

In FlexUnit 4.5.1, this approach changed to using [Rule]'s like so:

public class MyTestNGTest
{
    [Rule]
    public function paramaterizedRule:ParamaterizedRule = new ParamaterizedRule();

    ...
 }

However, I can't seem to see an actual implementation of IMethodRule for paramaterized tests (that example is fictional).

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