Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

...

Sequences are an attempt to reduce the pain associated with these tests. They provide a simpler method of defining the steps that need to happen in order, and potentially asynchronous, before we can assert. The sequence is still designed to test one thing, just like the other tests, but it acknowledges that some steps may need to occur first.

Approach

Wiki MarkupIn this example, we are going to write a single test for a login form. The login form will be created as a custom MXML component. We will instantiate the component in the method marked with {{\[Before\]}} and wait until the {{creationComplete}} event fires before beginning our test. Our test will set the username and password. Once the values have been committed, we will simulate the login button click and wait for a custom login event to be broadcast. Once that event is received, we will check that the password matches what we entered.

Create the Login Form

*Inside of your test runner project, browse to the sampleSuite/tests directory (the location where you previously created your TestCase1.as).
*Create a new folder named ‘mxml’
*In the mxml folder, create a new MXML component named LoginForm.mxml that extends Panel.
*Copy the following code into LoginForm.mxml

...

Code Block
actionscript
actionscript
    private var form:LoginForm;

Wiki Markup*Create a {{setup()}} method and mark it with the {{\[Before\]}} metadata. This method will be called before each of your test methods. In addition, annotate the {{\[Before\]}} metadata with {{async}} and {{ui}}. The {{async}} annotation notifies the runner this test is waiting on an some asynchronous behavior. The {{ui}} metadata notifies the runner this test contains ui interaction that must be completed.

Code Block
actionscript
actionscript
     [Before(async, ui)]
     public function setUp():void {
                              
     }

...

'''Note''': In the above code the async handler is given a method to call in response to the event being dispatched (i.e. pendUntilComplete is called when CREATION_COMPLETE is dispatched), and so the tests will not be run until this method has been called; however no actual functionality needs to reside within pendUntilComplete, therefore you end up with an extraneous function. An alternative way to achieve the same functionality, and one which has clearer intent, is to use Async.proceedOnEvent. You can replace form.addEventListener ... with Async.proceedOnEvent( this, form, FlexEvent.CREATION_COMPLETE ); - if you have been following the documentation from the beginning you will have already seen Async.proceedOnEvent being used in http://docs.flexunit.org/index.php?title=Using_Asynchronous_Startup#Asynchronous_SetUp_and_TearDown_Defined this code example.unmigrated-wiki-markup

*Create a method named {{tearDown()}} and mark it with the {{\[After\]}} metadata to remove the LoginForm instance from the test environment and set its reference to null. Once again, annotate the metadata with {{async}} and {{ui}}.

Code Block
actionscript
actionscript
     [After(async, ui)]
     public function tearDown():void {
          UIImpersonator.removeChild( form );                    
          form = null;
     }

...