BTA Flexing

My passion RIAs…………..Shardul Singh Bartwal

Unit Testing in Flex 4 application Using Flash-Builder 4

Posted by Shardul Singh Bartwal 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:-

package utils
{
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

1

3)Now I am createing a class with name MyTestCase1. See below:-
2

Click on the Browser button.

4)It will look as :-
3
Select the MyMath and click OK as below:-

Now it should look like:-
4

click on Next button.You will see like below:-
5

Click Finish.

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();
Assert.assertEquals(myMath.add(5,6),11);

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:-

6

Except this inside flash builder you will see a tab with title ‘FlexUnit Results’ Explore this for detail investigation.

Enjoy Flexing………….. 🙂

Advertisements

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: