Skip navigation
CompletlyClueless
Currently Being Moderated

Paramaterized Testing Issues

Nov 24, 2010 11:19 AM

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(InitializationErr or.as:50)
at org.flexunit.internals.builders::MetaDataBuilder/createInitialization Error(MetaDataBuilder.as:209)
at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSigna ture(MetaDataBuilder.as:179)
at org.flexunit.internals.builders::MetaDataBuilder/buildRunner(MetaData Builder.as:146)
at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass(MetaD ataBuilder.as:115)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(Runn erBuilderBase.as:63)
at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runne rForClass(AllDefaultPossibilitiesBuilder.as:106)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(Runn erBuilderBase.as:63)
at org.flexunit.runners.model::RunnerBuilderBase/localRunners(RunnerBuil derBase.as:119)
at org.flexunit.runners.model::RunnerBuilderBase/runners(RunnerBuilderBa se.as:87)
at org.flexunit.runners::Suite(Suite.as:170)
at org.flexunit.internals.builders::MetaDataBuilder/buildWithSecondSigna ture(MetaDataBuilder.as:174)
at org.flexunit.internals.builders::MetaDataBuilder/buildRunner(MetaData Builder.as:146)
at org.flexunit.internals.builders::MetaDataBuilder/runnerForClass(MetaD ataBuilder.as:115)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(Runn erBuilderBase.as:63)
at org.flexunit.internals.builders::AllDefaultPossibilitiesBuilder/runne rForClass(AllDefaultPossibilitiesBuilder.as:106)
at org.flexunit.runners.model::RunnerBuilderBase/safeRunnerForClass(Runn erBuilderBase.as:63)
at org.flexunit.runners.model::RunnerBuilderBase/localRunners(RunnerBuil derBase.as:119)
at org.flexunit.runners.model::RunnerBuilderBase/runners(RunnerBuilderBa se.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(FlexUnit TestRunnerUI.mxml:148)
**[ at FlexUnitApplication/onCreationComplete(FlexUnitApplication.mxml:26) ]
**[ at FlexUnitApplication/___FlexUnitApplication_Application1_creationCompl ete(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(LayoutManage r.as:1072)

 
Replies
  • Currently Being Moderated
    Nov 24, 2010 12:01 PM   in reply to CompletlyClueless

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

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2010 12:06 PM   in reply to CompletlyClueless

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2010 12:09 PM   in reply to CompletlyClueless

    Great. Just updating that core swc file should take care of everything. You could replace the version FlashBuilder uses directly, or just drop it in the libs folder of your project which will effectively trump the version that comes with Flash Builder.

     

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 24, 2010 12:14 PM   in reply to CompletlyClueless

    You got it.

     

    Mike

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points