8 Replies Latest reply: Nov 24, 2010 12:14 PM by Michael Labriola RSS

    Paramaterized Testing Issues

    CompletlyClueless

      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(MetaDataBuilde r.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(AllDefault PossibilitiesBuilder.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(AllDefault PossibilitiesBuilder.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:14 8)
      **[ at FlexUnitApplication/onCreationComplete(FlexUnitApplication.mxml:26) ]
      **[ at FlexUnitApplication/___FlexUnitApplication_Application1_creationComplete(FlexUnitApplicat ion.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)