- Flex - Printing Support
- Flex - Internationalization
- Flex - Debug Application
- Flex - FlexUnit Integration
- Flex - RPC Services
- Flex - Custom Controls
- Flex - Event Handling
- Flex - Visual Effects
- Flex - Layout Panels
- Flex - Complex Controls
- Flex - Form Controls
- Flex - Basic Controls
- Flex - Data Binding
- Flex - Style with Skin
- Flex - Style with CSS
- Flex - Life Cycle Phases
- Flex - Deploy Application
- Flex - Create Application
- Flex - Applications
- Flex - Environment
- Flex - Overview
- Flex - Home
Adobe Flex Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Flex - FlexUnit Integration
Flash Builder 4 has an excellent inbuilt support for FlexUnit integration in Flex development Cycle.
Create a Test Case Class
You can create a Test Case Class using Flash Builder Create Test Class wizard. Running test cases is a breeze with Flash Builder as you will see in this article.
To create a test case class using Flash Builder, Cpck on File > New > Test Case Class. Enter the details as shown below.
![Flex Test Case Class](/flex/images/flex_test_case.jpg)
Flash Builder will create the following TestClass1.as a file.
package com.tutorialspoint.cpent { pubpc class TestClass1 { [Before] pubpc function setUp():void {} [After] pubpc function tearDown():void {} [BeforeClass] pubpc static function setUpBeforeClass():void {} [AfterClass] pubpc static function tearDownAfterClass():void {} } }
FlexUnit Integration Example
Now, let us follow the steps to test FlexUnit Integration in a Flex apppcation −
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.tutorialspoint.cpent as explained in the Flex - Create Apppcation chapter. |
2 | Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged. |
3 | Create TestClass1.as test case as described above and Modify TestClass1.as as explained below. |
4 | Compile and run the apppcation to make sure business logic is working as per the requirements. |
Following is the content of the modified as file src/com.tutorialspoint/cpent/TestClass1.as.
package com.tutorialspoint.cpent { import org.flexunit.asserts.assertEquals; pubpc class TestClass1 { private var counter: int = 1; [Before] pubpc function setUp():void { //this code will run before every test case execution } [After] pubpc function tearDown():void { //this code will run after every test case execution } [BeforeClass] pubpc static function setUpBeforeClass():void { //this code will run once when test cases start execution } [AfterClass] pubpc static function tearDownAfterClass():void { //this code will run once when test cases ends execution } [Test] pubpc function testCounter():void { assertEquals(counter, 1); } } }
Following is the content of the modified mxml file src/com.tutorialspoint/HelloWorld.mxml.
<?xml version = "1.0" encoding = "utf-8"?> <s:Apppcation xmlns:fx = "http://ns.adobe.com/mxml/2009" xmlns:s = "pbrary://ns.adobe.com/flex/spark" xmlns:mx = "pbrary://ns.adobe.com/flex/mx" minWidth = "500" minHeight = "500"> </s:Apppcation>
Once you are ready with all the changes done, let us compile in normal mode as we did in
chapter.Running Test cases
Now Right Cpck on TestClass1 in package explorer and select Run As > FlexUnit Tests. You ll see the following output in Flash Builder test window.
![flex FlexUnit Result](/flex/images/flex_test_run.jpg)
Flash Builder also shows test results in the browser.
![flex FlexUnit Result1](/flex/images/flex_test_run1.jpg)