1 Reply Latest reply on Jul 1, 2010 2:56 PM by mlabriola

    is it possible to run test suite B based on test Suite A?

    asafdsadfasddfsas Level 1

      There are 2 test suites:

       

      A & B

       

      I want to run the test suite B only when test suite A is successful.

       

      Please give me some hints how to achieve this.

        • 1. Re: is it possible to run test suite B based on test Suite A?
          mlabriola Level 4

          There isn't any official way to do this at this time. Pre-release we supported this but tools like FlashBuilder and some other interface points needed to know, before the testing began, how many tests they were expecting and that sort of derailed us.

           

          However, if you want to know how to do this in a quick and dirty sort of way, and you don't mind doing a little work, here is an approach you can refine.

           

          First, create yourself a static class or a singleton which implements IRunListener. Objects of this type can receive updates as tests run, fail, etc. So in your object you could keep track of any failure conditions which were important decision points. Call the addListener() method of the FlexUnitCore and pass your object in.

           

          var core:FlexUnitCore = new FlexUnitCore()

          core.addListener( mySpecialSingletonListener.getInstance() );

           

          This will register your object to receive the updates I mention above. Next step, create a new runner which extends Suite. So, for example PotentiallyIgnoreMeRunner extends Suite.

           

          Inside of here you are going to add a new function which I have provided here called ignoreRecursively:

           

          protected function ignoreRecursively( notifier:IRunNotifier, description:IDescription ):void {

            if ( description.isTest ) {

              notifier.fireTestIgnored( description );

            } else {

              var children:Array = description.children;

              for ( var i:int=0; i<children.length; i++ ) {

                ignoreRecursively( notifier, children[ i ] );

              }

            }

          }

           

          Basically, it will cause each test in this suite to be marked as ignored in the output and will not execute it.

           

          Then you will need to override the protected runChild() method to do something like this:

           

          override protected function runChild( child:*, notifier:IRunNotifier, childRunnerToken:AsyncTestToken ):void {

           

            var mySpecialSingleton:MySpecialSingleton = MySpecialSingleton.getInstance();

           

            //Here you will need to call some function that accepts the current testClass and decides if it should be run or ignored

           

            if ( mySpecialSingleton.shouldIRunThisSuite( testClass ) ) {

              super.runChild( child, notifier, childRunnerToken );

            } else {

              var description:IDescription = describeChild( child );

           

              ignoreRecursively( notifier, description );

              childRunnerToken.sendResult();

            }

          }

           

          Almost done, decorate your suite classes to use your new runner instead of ours:

           

          [Suite]

          [RunWith("some.package.PotentiallyIgnoreMeRunner")]

          public class SuiteB {

          }

           

          Finally, make sure you include a reference to the PotentiallyIgnoreMeRunner somewhere in your application. Metadata is just a string to FlashBuilder and it will not automatically know to include the PotentiallyIgnoreMeRunner in the final swf file.

           

          I just did a quick prototype and it will successfully ignore all tests based on the result of another.

           

          Mike