“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:
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:
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”.
Hi,
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();
req.clearSession();
***************
public function clearSession():void
{
var _remoteHttp : HTTPService = new HTTPService();
_remoteHttp.url = ApplicationCommonModel.getInstance().serverContextUrl+’logout’;
_remoteHttp.method = “POST”;
_remoteHttp.resultFormat = “e4x”;
_remoteHttp.addEventListener(
ResultEvent.RESULT, function (event:ResultEvent):void{
validateUser(mainResult.getInstance()._loginParams);
} );
_remoteHttp.addEventListener(
FaultEvent.FAULT, function (event:FaultEvent):void{
validateUser(mainResult.getInstance()._loginParams);
} );
_remoteHttp.send();
}
could u please tel me how write test case for this block of code.?
Thanks & Regards,
Bhuvana