Unit Testing in Flex 4 application Using Flash-Builder 4
Posted by shardulbartwal on June 30, 2011
Inside the Flash builder 4 simply create a new Flex project,I am naming it as UnitTestingDemo.
1)I have created a class with name MyMath.as under the folder the utils,I am putting it inside the utils just for practice.
Which is as below:-
public class MyMath
public function MyMath()
public function add(num1 : Number,num2 : Number) : Number
return num1 + num2;
public function multiply(num1 : Number,num2 : Number) : Number
return num1 * num2;
2)Now go to File>New>Test Case Class
3)Now I am createing a class with name MyTestCase1. See below:-
Click on the Browser button.
4)It will look as :-
Select the MyMath and click OK as below:-
Now it should look like:-
click on Next button.You will see like below:-
5)Now on the Package Explorer on the left you will MyTestCase1.as under the folder flexUnitTests.You will see there a method with name testAdd() inside this class.
Now I am going to check for my expected positive result from this method.As we know that 5+6=11.So I have written like this inside this method:-
var myMath : MyMath = new MyMath();
6)Now Click on the MyTestCase1.as and select it on the left side Package Explorer.Right Mouse click on this.You will see there a menu with title ‘Execute Flex UnitTests’ click on this.If every thing goes well you will see like below in your browser:-
Except this inside flash builder you will see a tab with title ‘FlexUnit Results’ Explore this for detail investigation.