Skip to main content
Participant
Nov 24, 2010 7:19 PM UTC
Answered

Paramaterized Testing Issues

Hi I'm new to unit testing so I've been having issues...

I am trying to run tests with parameters and I have fixed the errors up to here by browsing the net, but I can't find why this isn't working...

Any help is greatly appreciated, thanks in advance=D

Here is the test class:

package flexUnitTests
{
    import flexunit.framework.Assert;
    import Game.Rand;
    import org.flexunit.runners.Parameterized;
   
    [RunWith("org.flexunit.runners.Parameterized")]
    public class RandTest
    {       
        private var classToTestRef : Rand;
        private var foo:Parameterized;
        public static var inputInt:Array= [ [ 1, 20 ], [ 2, 8 ], [ 16, 18 ], [ 1, 100 ], [ 16, 80 ]];
       
        [Test(dataProvider="inputInt")]
        public function testIntWithinRange(nMin:Number, nMax:Number):void
        {
            classToTestRef = new Rand();
            var bInRange:Boolean = false;
            var Random:int = classToTestRef.Int(nMax);
            if((Random > nMin-1) && (Random < nMax-1)){ bInRange=true;}
            Assert.assertTrue(bInRange);
            Random = classToTestRef.Int(nMin,nMax);
            if((Random > nMin-1) && (Random < nMax-1)){ bInRange=true;}
            Assert.assertTrue(bInRange);
        }
       
        [Test]
        public function testStore():void
        {
            Assert.assertNotNull(classToTestRef.Stored());
        }
       
        public static function inputRandomSelection():Array {
            return [ [ [2,3,5,7], 1, true ], [[2,3,5,7], 2, true ], [[2,3,5,7], 3, true ], [[2,3,5,7], 4, false ], [[2,2,7,7], 3, false ] ];
        }
       
        [Test(dataProvider="inputRandomSelection")]
        public function testRandomSelectionLengthsAreCorrect(aVariables:Array, iAmount:int, bShouldWork:Boolean):void
        {
            var iCounter:int;
            var Selection:Array = classToTestRef.RandomSelection(aVariables, iAmount);
            //Make sure that iAmount is greater then iVarables.length
            var bAmountHigher:Boolean = false;
            if(iAmount > aVariables.length){ bAmountHigher = true; }
            if(bShouldWork == true){Assert.assertTrue(bAmountHigher);}
            else {Assert.assertFalse(bAmountHigher);}
                       
            //The correct number of varibles were returned
            var bCorrectNumber:Boolean = false;
            if (Selection.length == iAmount){bCorrectNumber = true;}
            if(bShouldWork == true){Assert.assertTrue(bCorrectNumber);}
            else {Assert.assertFalse(bCorrectNumber);}
        }
        [Test(dataProvider="inputRandomSelection")]
        public function testRandomSelectionArraysAreCorrect(aVariables:Array, iAmount:int, bShouldWork:Boolean):void{
            var iCounter:int, iCounter2:int;
            var Selection:Array = classToTestRef.RandomSelection(aVariables, iAmount);
            //Check that all the values reurned are unique
            var bUnique:Boolean = true;
            for(iCounter = 0; iCounter < Selection.length; iCounter++){
                for(iCounter2 = 0; iCounter2 < Selection.length; iCounter2++){
                    if((Selection[iCounter] == Selection[iCounter2]) && (iCounter!=iCounter2)){ bUnique = false; }
                }
            }
            if(bShouldWork == true){Assert.assertTrue(bUnique);}
            else {Assert.assertFalse(bUnique);}
           
            //All numbers returned were from aVariables
            var bFromSource:Boolean = true;
            for(iCounter = 0; iCounter < Selection.length; iCounter++){
                if(aVariables.indexOf(Selection[iCounter]) == -1){ bFromSource = false; }
            }
            if(bShouldWork == true){Assert.assertTrue(bFromSource);}
            else {Assert.assertFalse(bFromSource);}
        }
    }
}

And here is the trace:

Error: Custom runner class org.flexunit.runners.Parameterized cannot be instantiated
at org.flexunit.internals.runners::InitializationError(InitializationError.as:50)
at org.flexunit.internals.builders::MetaDataBuilder/createInitializationError(MetaDataBuilder.as:209)
at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSignature(MetaDataBuilder.as:179)
at org.flexunit.internals.builders::MetaDataBuilder/buildRunner(MetaDataBuilder.as:146)
at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass(MetaDataBuilder.as:115)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(RunnerBuilderBase.as:63)
at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runnerForClass(AllDefaultPossibilitiesBuilder.as:106)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(RunnerBuilderBase.as:63)
at org.flexunit.runners.model::RunnerBuilderBase/localRunners(RunnerBuilderBase.as:119)
at org.flexunit.runners.model::RunnerBuilderBase/runners(RunnerBuilderBase.as:87)
at org.flexunit.runners::Suite(Suite.as:170)
at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSignature(MetaDataBuilder.as:174)
at org.flexunit.internals.builders::MetaDataBuilder/buildRunner(MetaDataBuilder.as:146)
at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass(MetaDataBuilder.as:115)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(RunnerBuilderBase.as:63)
at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runnerForClass(AllDefaultPossibilitiesBuilder.as:106)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(RunnerBuilderBase.as:63)
at org.flexunit.runners.model::RunnerBuilderBase/localRunners(RunnerBuilderBase.as:119)
at org.flexunit.runners.model::RunnerBuilderBase/runners(RunnerBuilderBase.as:87)
at org.flexunit.runners::Suite(Suite.as:170)
at org.flexunit.runner::Request$/classes(Request.as:201)
at Function/http://adobe.com/AS3/2006/builtin::apply
at org.flexunit.runner::FlexUnitCore/runClasses(FlexUnitCore.as:191)
at Function/http://adobe.com/AS3/2006/builtin::apply
at org.flexunit.runner::FlexUnitCore/run(FlexUnitCore.as:171)
at flexunit.flexui::FlexUnit4TestRunner/run(FlexUnit4TestRunner.as:75)
at flexunit.flexui::FlexUnitTestRunnerUI/runWithFlexUnit4Runner(FlexUnitTestRunnerUI.mxml:148)
**[ at FlexUnitApplication/onCreationComplete(FlexUnitApplication.mxml:26) ]
**[ at FlexUnitApplication/___FlexUnitApplication_Application1_creationComplete(FlexUnitApplication.mxml:7) ]
at flash.events::EventDispatcher/dispatchEventFunction
at flash.events::EventDispatcher/dispatchEvent
at mx.core::UIComponent/dispatchEvent(UIComponent.as:12266)
at mx.core::UIComponent/set initialized(UIComponent.as:1577)
at mx.managers::LayoutManager/doPhasedInstantiation(LayoutManager.as:759)
at mx.managers::LayoutManager/doPhasedInstantiationCallback(LayoutManager.as:1072)

This topic is closed to new replies. Start a new post to keep the conversation going.
mlabriolaCorrect answer
Participating Frequently
Nov 24, 2010 8:06 PM UTC

It just came with Flash Builder 4, I was using Flex 3 before but upgraded cause I'm wanting to try TDD.


No problem. The version that came with Flash Builder 4 was the 4.0 release version of FlexUnit. We didn't introduce parameterized testing until the 4.1 beta version. If I run your code (with references to your Rand class commented out) it all works as expected which is why I guessed we were on different versions.

Go here:

http://www.flexunit.org/?page_id=14

Download the 4.1 RC1 code (which will be released very shortly). You will get a bunch of libraries and docs in the zip file. You can ignore most of that for now. All you really need is the flexunit-core-*.swc file. Extract that one and drop it in the libs folder of your project and your code will likely run just fine.

Mike

8 replies

Participant
Nov 24, 2010 7:46 PM UTC

Oh, also I'm using Flahs Builder 4 build 272416 =)

Translate
Participating Frequently
Nov 24, 2010 8:01 PM UTC

Do you know what FlexUnit build you are using or is it just the one that came with Flash Builder?

Mike

Translate
Participant
Nov 24, 2010 8:02 PM UTC

It just came with Flash Builder 4, I was using Flex 3 before but upgraded cause I'm wanting to try TDD.

Translate