• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Paramaterized Testing Issues

New Here ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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)

TOPICS
FlexUnit

Views

4.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Nov 24, 2010 Nov 24, 2010

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 mos

...

Votes

Translate

Translate
New Here ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

In the Plug-ins tab of the Flash Builder Installation Details, it claims that I have version 4.0.0.272416 of everything to do with flexunit.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

Yep, I posted my last post after you posted yours which made it alot more redundant... Either way, I don't have the error any more... I have a BUNCH more to keep me busy now! Thanks a bunch Mike!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Nov 24, 2010 Nov 24, 2010

Copy link to clipboard

Copied

LATEST

You got it.

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines