Skip to main content
Participating Frequently
September 30, 2010
Answered

Error while running Parameterized test

  • September 30, 2010
  • 1 reply
  • 5612 views

Hi,

I'm currently working on a really simple Parameterized TestCase. I'm using flexunit 4.0-rc1 and flexmojos 3.5.0.

When I do 'mvn clean test' I get the following error:

<testsuite errors="0" failures="1" name="com.finams.bnpflexlib.utils.StringUtilsTest" tests="1" time="0">   <testcase name="initializationError" time="0">     <failure message="Custom runner class org.flexunit.runners.Parameterized cannot be instantiated" type="com.finams.bnpflexlib.utils.StringUtilsTest">Error: Custom runner class org.flexunit.runners.Parameterized cannot be instantiated      at org.flexunit.internals.runners::InitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/createInitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSignature()      at org.flexunit.internals.builders::MetaDataBuilder/buildRunner()      at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/localRunners()      at org.flexunit.runners.model::RunnerBuilderBase/runners()      at org.flexunit.runners::Suite()      at org.flexunit.runner::Request$/classes()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/runClasses()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/run()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.sonatype.flexmojos.unitestingsupport.flexunit4::FlexUnit4Listener/run()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-flexunit4/src/main/flex/org/sonatype/flexmojos/unitestingsupport/flexunit4/FlexUnit4Listener.as:42]      at org.sonatype.flexmojos.unitestingsupport::SocketReporter/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/SocketReporter.as:243]      at org.sonatype.flexmojos.unitestingsupport::TestApplication/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/TestApplication.as:40]      at flash.events::EventDispatcher/dispatchEventFunction()      at flash.events::EventDispatcher/dispatchEvent()      at mx.core::UIComponent/dispatchEvent()      at mx.core::UIComponent/set initialized()      at mx.managers::LayoutManager/doPhasedInstantiation()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at mx.core::UIComponent/callLaterDispatcher2()      at mx.core::UIComponent/callLaterDispatcher()</failure>   </testcase> </testsuite>

Here is my TestCase (StringUtils is a simple class with a single method that converts numbers to strings, I did it to manage the specific case of a NaN parameter):

package com.finams.bnpflexlib.utils {      import org.flexunit.Assert;      import org.flexunit.runners.Parameterized;      import com.finams.bnpflexlib.utils.StringUtils;            [RunWith("org.flexunit.runners.Parameterized")]      public class StringUtilsTest      {           [Datapoints]           static public var referential:Array = [                {numeric: 0, alpha: '0'},                {numeric: 1500, alpha: '1500'},                {numeric: 42, alpha: '42'},                {numeric: 15.15, alpha: '15.15'},                {numeric: 999, alpha: '999'},                {numeric: 17.0123456789, alpha: '17.0123456789'},                {numeric: 123456789, alpha: '123456789'},                {numeric: 0.00000000001, alpha: '0.00000000001'},                {numeric: -1, alpha: '-1'},                {numeric: 0.00000000015, alpha: '0.00000000015'},                {numeric: -1.01, alpha: '-1.01'},                {numeric: 0.12345678912, alpha: '0.12345678912'},                {numeric: -123456789, alpha: '-123456789'},                {numeric: 0.0, alpha: '0.0'},                {numeric: -1.123456789, alpha: '-1.123456789'},                {numeric: -0.0, alpha: '-0.0'}           ];                      public function StringUtilsTest() {}           [Test(description="Ensure that a NaN number will produce an empty string.")]           public function checkNbToStringWithNaNParameter():void           {                var result:String;                                result = StringUtils.nbToString(NaN);                                Assert.assertEquals(result, '');           }                      [Ignore]           [Test(dataprovider="referential", description="Check conversion with a set of values")]           public function checkNumbers(nb:Number, ref:String):void           {                var result:String;                                result = StringUtils.nbToString(nb);                                Assert.assertEquals('Conversion fault: expected ' + ref + ', got ' + nb.toString(),                               result,                               'ref');           }      } }

I wonder what's wrong...

This topic has been closed for replies.
Correct answer mlabriola

I corrected what was wrong but still have the same problem:

<testsuite errors="0" failures="1" name="com.finams.bnpflexlib.utils.StringUtilsTest" tests="1" time="0">   <testcase name="initializationError" time="0">     <failure message="Custom runner class org.flexunit.runners.Parameterized cannot be instantiated" type="com.finams.bnpflexlib.utils.StringUtilsTest">Error: Custom runner class org.flexunit.runners.Parameterized cannot be instantiated      at org.flexunit.internals.runners::InitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/createInitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSignature()      at org.flexunit.internals.builders::MetaDataBuilder/buildRunner()      at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/localRunners()      at org.flexunit.runners.model::RunnerBuilderBase/runners()      at org.flexunit.runners::Suite()      at org.flexunit.runner::Request$/classes()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/runClasses()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/run()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.sonatype.flexmojos.unitestingsupport.flexunit4::FlexUnit4Listener/run()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-flexunit4/src/main/flex/org/sonatype/flexmojos/unitestingsupport/flexunit4/FlexUnit4Listener.as:42]      at org.sonatype.flexmojos.unitestingsupport::SocketReporter/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/SocketReporter.as:243]      at org.sonatype.flexmojos.unitestingsupport::TestApplication/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/TestApplication.as:40]      at flash.events::EventDispatcher/dispatchEventFunction()      at flash.events::EventDispatcher/dispatchEvent()      at mx.core::UIComponent/dispatchEvent()      at mx.core::UIComponent/set initialized()      at mx.managers::LayoutManager/doPhasedInstantiation()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at mx.core::UIComponent/callLaterDispatcher2()      at mx.core::UIComponent/callLaterDispatcher()</failure>   </testcase> </testsuite>

The new version of my test case:

package com.finams.bnpflexlib.utils {      import org.flexunit.Assert;      import org.flexunit.runners.Parameterized;      import com.finams.bnpflexlib.utils.StringUtils;           [RunWith("org.flexunit.runners.Parameterized")]      public class StringUtilsTest      {           public var foo:Parameterized;                     [Datapoints]           static public var referential:Array = [                [0,                '0'],                [1500,                '1500'],                [42,                '42'],                [15.15,           '15.15'],                [999,                '999'],                [17.0123456789, '17.0123456789'],                [123456789,      '123456789'],                [0.00000000001, '0.00000000001'],                [-1,                '-1'],                [0.00000000015, '0.00000000015'],                [-1.01,           '-1.01'],                [0.12345678912, '0.12345678912'],                [-123456789,      '-123456789'],                [0.0,                '0.0'],                [-1.123456789,      '-1.123456789'],                [-0.0,                '-0.0']/* ,                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''],                [, ''], */           ];                     public function StringUtilsTest() {}           [Test(description="Ensure that a NaN number will produce an empty string.")]           public function checkNbToStringWithNaNParameter():void           {                var result:String;                               result = StringUtils.nbToString(NaN);                               Assert.assertEquals(result, '');           }                     [Ignore]           [Test(dataProvider="referential", description="Check conversion with a set of values")]           public function checkNumbers(nb:Number, ref:String):void           {                var result:String;                               result = StringUtils.nbToString(nb);                               Assert.assertEquals('Conversion fault: expected ' + ref + ', got ' + nb.toString(),                                         result,                                         'ref');           }      } }

[EDIT]

I just tried to put a flexunit-4.0.0 swc file and changed my declared dependency in my pom.xml. I still have the same problem.

[/EDIT]

What should I do then ?


the dot zero release of flexunit doesnt have parameterized testing, only dot one versions. so using the swc you mention in your edit will fail. i am also concerned as your post of error messages shows a developers name.. dmoore... this means it is not a release build in any way. iall release builds are built from our server. somewhere you are getting a really old development lib and not a approved version

can you try to grab a version from builds.flexunit.org

mike

1 reply

Participating Frequently
September 30, 2010

in actionscript metadata is a string. since there isnt an actual reference to the parameterized runner class anywhere in your code, the linker isnt including it in the final swf. when the metadata string is evaluated at runtime, it cannot find the runner class in memory as it will not exist in that swf

two options. ensure the runner is linked in by making reference to it in the test case somewhere. use the second release candidate where we force it to be linked in because a lot of people were having similar issues

hope that explains and helps

mike

Participating Frequently
September 30, 2010

First, thanks for your answer.

I saw in the wiki of flexunit.org that you declare a private property named foo of type Parameterized.

I did it, but I still have the problem :

<testsuite errors="0" failures="1" name="com.finams.bnpflexlib.utils.StringUtilsTest" tests="1" time="0">   <testcase name="initializationError" time="0">     <failure message="Custom runner class org.flexunit.runners.Parameterized cannot be instantiated" type="com.finams.bnpflexlib.utils.StringUtilsTest">Error: Custom runner class org.flexunit.runners.Parameterized cannot be instantiated      at org.flexunit.internals.runners::InitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/createInitializationError()      at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSignature()      at org.flexunit.internals.builders::MetaDataBuilder/buildRunner()      at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass()      at org.flexunit.runners.model::RunnerBuilderBase/localRunners()      at org.flexunit.runners.model::RunnerBuilderBase/runners()      at org.flexunit.runners::Suite()      at org.flexunit.runner::Request$/classes()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/runClasses()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.flexunit.runner::FlexUnitCore/run()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at org.sonatype.flexmojos.unitestingsupport.flexunit4::FlexUnit4Listener/run()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-flexunit4/src/main/flex/org/sonatype/flexmojos/unitestingsupport/flexunit4/FlexUnit4Listener.as:42]      at org.sonatype.flexmojos.unitestingsupport::SocketReporter/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/SocketReporter.as:243]      at org.sonatype.flexmojos.unitestingsupport::TestApplication/runTests()[/home/nexus/flexmojos/trunk/target/checkout/flexmojos-testing/flexmojos-unittest-support/src/main/flex/org/sonatype/flexmojos/unitestingsupport/TestApplication.as:40]      at flash.events::EventDispatcher/dispatchEventFunction()      at flash.events::EventDispatcher/dispatchEvent()      at mx.core::UIComponent/dispatchEvent()      at mx.core::UIComponent/set initialized()      at mx.managers::LayoutManager/doPhasedInstantiation()      at Function/http://adobe.com/AS3/2006/builtin::apply()      at mx.core::UIComponent/callLaterDispatcher2()      at mx.core::UIComponent/callLaterDispatcher()</failure>   </testcase> </testsuite>

Here is my updated TestCase:

package com.finams.bnpflexlib.utils {      import org.flexunit.Assert;      import org.flexunit.runners.Parameterized;      import com.finams.bnpflexlib.utils.StringUtils;            [RunWith("org.flexunit.runners.Parameterized")]      public class StringUtilsTest      {           private var foo:Parameterized;                      [Datapoints]           static public var referential:Array = [                {numeric: 0,                     alpha: '0'},                {numeric: 1500,                alpha: '1500'},                {numeric: 42,                     alpha: '42'},                {numeric: 15.15,                alpha: '15.15'},                {numeric: 999,                     alpha: '999'},                {numeric: 17.0123456789,      alpha: '17.0123456789'},                {numeric: 123456789,           alpha: '123456789'},                {numeric: 0.00000000001,      alpha: '0.00000000001'},                {numeric: -1,                     alpha: '-1'},                {numeric: 0.00000000015,      alpha: '0.00000000015'},                {numeric: -1.01,                alpha: '-1.01'},                {numeric: 0.12345678912,      alpha: '0.12345678912'},                {numeric: -123456789,           alpha: '-123456789'},                {numeric: 0.0,                     alpha: '0.0'},                {numeric: -1.123456789,      alpha: '-1.123456789'},                {numeric: -0.0,                alpha: '-0.0'}/* ,                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''},                {numeric: , alpha: ''}, {numeric: , alpha: ''}, */           ];                      public function StringUtilsTest() {}           [Test(description="Ensure that a NaN number will produce an empty string.")]           public function checkNbToStringWithNaNParameter():void           {                var result:String;                                result = StringUtils.nbToString(NaN);                                Assert.assertEquals(result, '');           }                      [Ignore]           [Test(dataprovider="referential", description="Check conversion with a set of values")]           public function checkNumbers(nb:Number, ref:String):void           {                var result:String;                                result = StringUtils.nbToString(nb);                                Assert.assertEquals('Conversion fault: expected ' + ref + ', got ' + nb.toString(),                                         result,                                         'ref');           }      } }

I'm not sure if I can use another version of flexunit since 4.0-rc1 seems to be a flexmojos restriction.

Participating Frequently
September 30, 2010

Okay, I see two more problems

Problem #1, [Test(dataprovider= ... the 'p' in dataProvider should be capitalized. If you get a chance, also file this as an enhancement so we can look for either or at least warn.

Problem #2, the dataprovider is not formed correctly. It needs to be an array of arrays, so:

static public var referential:Array = [

[0, '0'],

[1500, '1500']

];

I think that will fix the situation.
Another issue we clearly have is that, in the case where something is marked Ignore, we shouldn't even bother going to look for the dataProvider.
I think this will get you running,
Mike