• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Strange behaviour when running parameterized test

Guest
Oct 23, 2011 Oct 23, 2011

Copy link to clipboard

Copied

Hello,

I am using Flex 4.5 and FlexUnit 4.1 inside of the Flashdevelop IDE and I am experiencing some very strange behaviour.

If I have 5 parameters to my test the test runs fine. When I add a sixth parameter of the type Array, I get the following error:

"TypeError: Error #1009: Cannot access a property or method of a null object reference."

Please see below for my example code.

The following parameterized test case runs without a problem:

package {

    import org.flexunit.runners.Parameterized;

    [RunWith('org.flexunit.runners.Parameterized')]

    public class ParameterizedTest {

        [Parameters]

        public static var testData:Array = [

            [1,1,new Array(),1,1]

        ];

        public function ParameterizedTest(

            param1:uint,

            param2:uint,

            param3:Array,

            param4:uint,

            param5:uint

        ):void {

        }

        [Test]

        public function testOne():void {

            // Test to go here.

        }

    }

}

When I add an Array as the sixth parameter :

package {

    import org.flexunit.runners.Parameterized;

   

   

    [RunWith('org.flexunit.runners.Parameterized')]

    public class ParameterizedTest {

        [Parameters]

        public static var testData:Array = [

            [1,1,new Array(),1,1,new Array()]

        ];

       

       

        public function ParameterizedTest(

            param1:uint,

            param2:uint,

            param3:Array,

            param4:uint,

            param5:uint,

            param6:Array

        ):void {

        }

       

       

        [Test]

        public function testOne():void {

            // Test to go here.

        }

    }

}

I get this error :

com.berog.proj_drum_machine.tests.matrix_test_suite.test_cases::MatrixConstructorTest.testOne (1,1,,1,1,) .

TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at flex.lang.reflect::Constructor/newInstanceApply()

    at TestClassRunnerForParameters/createTest()

    at org.flexunit.runners::BlockFlexUnit4ClassRunner/methodBlock()

    at org.flexunit.runners::BlockFlexUnit4ClassRunner/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Parameterized/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Suite/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Suite/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runner::FlexUnitCore/beginRunnerExecution()

    at org.flexunit.runner::FlexUnitCore/runRunner()

    at org.flexunit.runner::FlexUnitCore/runRequest()

    at org.flexunit.runner::FlexUnitCore/runClasses()

    at Function/http://adobe.com/AS3/2006/builtin::apply()

    at org.flexunit.runner::FlexUnitCore/run()

    at com.berog.proj_drum_machine.tests::TestMain()

com.berog.proj_drum_machine.tests.matrix_test_suite.test_cases::MatrixConstructorTest.testOne (1,1,,1,1,) E

Time: 0.013

There was 1 failure:

1 com.berog.proj_drum_machine.tests.matrix_test_suite.test_cases::MatrixConstructorTest.testOne (1,1,,1,1,) TypeError: Error #1009: Cannot access a property or method of a null object reference.

    at flex.lang.reflect::Constructor/newInstanceApply()

    at TestClassRunnerForParameters/createTest()

    at org.flexunit.runners::BlockFlexUnit4ClassRunner/methodBlock()

    at org.flexunit.runners::BlockFlexUnit4ClassRunner/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Parameterized/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Suite/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runners::Suite/runChild()

    at org.flexunit.internals.runners::ChildRunnerSequencer/executeStep()

    at org.flexunit.internals.runners.statements::StatementSequencer/handleChildExecuteComplete()

    at org.flexunit.internals.runners.statements::StatementSequencer/evaluate()

    at org.flexunit.runners::ParentRunner/run()

    at org.flexunit.runner::FlexUnitCore/beginRunnerExecution()

    at org.flexunit.runner::FlexUnitCore/runRunner()

    at org.flexunit.runner::FlexUnitCore/runRequest()

    at org.flexunit.runner::FlexUnitCore/runClasses()

    at Function/http://adobe.com/AS3/2006/builtin::apply()

    at org.flexunit.runner::FlexUnitCore/run()

    at com.berog.proj_drum_machine.tests::TestMain()

FAILURES!!! Tests run: 1, 1 Failures:

Can anyone help me?

TOPICS
FlexUnit

Views

4.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 24, 2011 Oct 24, 2011

Copy link to clipboard

Copied

Thanks for including a test case. I will try to replicate this morning

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

Hi Mike,

Were you able to reproduce the errors I was experiencing?

Thanks,

Ben

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

Ben,

Yes, I have replicated them. Don't have an answer yet but do have replication.

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

Actually, I do see what's wrong.

When you call a method in the ActionScript universe, you can can usually do a function.apply() and pass it a variable number of args. Unfortunately, constructors are the one type of method where this doesn't work. You can't actually do an apply() so we have to fake it by having a map of static functions which each know how to apply a given number of arguments to the constructor. There is a check in the code that tests if the number of arguments you have exceeds what our static map knows how to apply.

It looks like that check should have thrown the error:

throw new ArgumentError("Sorry, we can't support constructors with more than " + argMap.length + " args out of the box... yes, its dumb, take a look at Constructor.as to modify on your own");

It didn't and I am guessing its because there is a border condition here. So, what happening is that we only support up to 5 arguments right now. That number is arbitrary. When it was written it just seemed like a reasonable number, however, this class was written before Parameterized testing was introduced.

Your three choices right now would be to use the TestNG style of Parameterized testing, which uses functions and not constructor args so it will not suffer this same fate, change the code and compile flexunit for yourself, or we could put a patched Constructor class in your project which fixes it. Longer term, I would like you to file a bug that we should increase the number to 10 or some other quasi-reasonable number. We will never be able to support an infinite number and we will always need to pick som arbitrary line in the sand. It just seems our line should be farther out.

Mike


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

Hi Mike,

Thanks so much for looking into this.

I think I'm going to make the change and recompile.

Where should I file the bug?

-Ben

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 25, 2011 Oct 25, 2011

Copy link to clipboard

Copied

LATEST

There is a flexunit category on bugs.adobe.com

Thanks,

mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines