Copy link to clipboard
Copied
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()
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...
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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()
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.
Copy link to clipboard
Copied
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']
];
Copy link to clipboard
Copied
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 ?
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks, you finally found the solution. I had to download flexunit 4.1.0-RC1 and put it in my local repository to make it work.
Copy link to clipboard
Copied
Glad to hear it.
One final note. The [DataPoints[ metadata you have in your example is extraneous. It won't hurt anything but it isn't needed either.
Cheers,
Mike
Copy link to clipboard
Copied
Hi,
Why do you say so ? do you mean that [Datapoint] is not interpreted by flexunit yet ? or do you mean the way I use it doesn't need to declare [Datapoint] ?
Copy link to clipboard
Copied
The DataPoint and DataPoints metadata is used by the Theory runner. It is not used by the Parameterized runner, so it is just being ignored in your case.
So it is used, just not in this context, so here it is ignored.
Mike
Copy link to clipboard
Copied
Interesting to know about [Datapoints]. Someone may wish to update the wiki at some stage? http://docs.flexunit.org/index.php?title=Parameterized_Test_Styles
Copy link to clipboard
Copied
agreed. side note. we are a completely volunteer unfunded open source project and the wiki is open to editing. so should anyone want to fix this before the limited team here can address, it is always greatly appreciated.
Copy link to clipboard
Copied
Ooh, didin't realise I can edit wiki - will get to it...
Copy link to clipboard
Copied
Hi,
Regarding using later versions of FlexUnit, you may want to take a look at:
Obviously, ideally all one needs is placing the new libraries in a repository and using (but sometimes this isn't an ideal World 😉 )
HTH, R.