Home > Uncategorized > “Is there a framework which would let me test the logic written within my mxml Application” – FlexUnit reloaded :)

“Is there a framework which would let me test the logic written within my mxml Application” – FlexUnit reloaded :)

This is a small post briefly explaining how one can test the logic written within an Application file. This post is a follow up on one of the questions raised very often “Is there a framework to test functions within mxml application in Flash Builder?”

The answer is a straight “YO” ! Here is the small example on how to achieve this.

1)Launch the Flash Builder4 and Create a flex project say “FlexUnitTesting”.

2) Open the file FlexUnitTesting.mxml and type the following code:

Application Code

Application Code

3) Save the application.

Note: I am using a sample function which just returns me a string. This can be extended to any complex logic even to the extent of testing custom component.

4)Context click on the FlexUnitTesting.mxml and select New->TestCase class.

5)You would be amazed to see the “Class to Test” being selected as “FlexUnitApplication” and the name of the test case pre-populated as”FlexUnitApplicationTest”.Now click NEXT.

6)You would see the public function ‘ sayIDidThat’, select the method and click FINISH.

7)The mxml editor would now point to stubs for the test case “FlexUnitApplicationTest” which got generated.

8)Verify the stub for the function ‘testSayIDidThat’:

Note: By default you would have the “fail” implementation for all the tests which would look like

fail(“Test method Not yet implemented”);

9)Write your test logic within the function ‘testSayIDidThat’ as follows:

Test the logic

Test the logic

10)Save and Run the tests(Context click on project -> Execute FlexUnit Tests).

Your result view would appear like this:



Yes, “You really Did That” 🙂

For more assistance and to know more about FlexUnit, launch Flash Builder hit F1 and search for “FlexUnit test Integration”.

Categories: Uncategorized
  1. Bhuvana
    December 7, 2009 at 1:20 pm

    This blog entry is very useful for me….
    I want to write test case for my application.
    and my code is below.

    var req :mainRequest = new mainRequest();



    public function clearSession():void

    var _remoteHttp : HTTPService = new HTTPService();
    _remoteHttp.url = ApplicationCommonModel.getInstance().serverContextUrl+’logout’;
    _remoteHttp.method = “POST”;
    _remoteHttp.resultFormat = “e4x”;

    ResultEvent.RESULT, function (event:ResultEvent):void{
    } );
    FaultEvent.FAULT, function (event:FaultEvent):void{
    } );


    could u please tel me how write test case for this block of code.?

    Thanks & Regards,

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: