May 25, 2021 Flex
Flash Builder 4 provides excellent built-in support for FlexUnit integration during the Flex development cycle.
You can use Flash Builder to create a test class wizard to create a test case class. /b10> Running test cases with Flash Builder is simple, as you'll see in this article.
To create a test case class using Flash Builder, click File and New and Test Case Class. /b12> Enter the details, as shown below.
Flash Builder creates the following TestClass1.as files.
package com.tutorialspoint.client { public class TestClass1 { [Before] public function setUp():void {} [After] public function tearDown():void {} [BeforeClass] public static function setUpBeforeClass():void {} [AfterClass] public static function tearDownAfterClass():void {} } }
Now let's test FlexUnit integration in the Flex application by following these steps:
Steps | Describe |
---|---|
1 | As described in the Flex - Create Applications section, create a project called HelloWorld under package com.tutorialspoint.client. |
2 | Modify HelloWorld.mxml, as described below. /b10> Keep the rest of the file unchanged. |
3 | Create a test case TestClass1.as described above and modify the TestClass1.as. |
4 | Compile and run the application to ensure that the business logic works as required. |
The following is the contents of the file modified to src / com.tutorialspoint / client / TestClass1.as file.
package com.tutorialspoint.client { import org.flexunit.asserts.assertEquals; public class TestClass1 { private var counter: int = 1; [Before] public function setUp():void { //this code will run before every test case execution } [After] public function tearDown():void { //this code will run after every test case execution } [BeforeClass] public static function setUpBeforeClass():void { //this code will run once when test cases start execution } [AfterClass] public static function tearDownAfterClass():void { //this code will run once when test cases ends execution } [Test] public function testCounter():void { assertEquals(counter, 1); } } }
The following is the contents of the modified mxml file src / com.tutorialspoint / HelloWorld.mxml.
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="500" minHeight="500"> </s:Application>
When you're ready for all your changes, follow the general pattern in the Flex - Create Apps chapter.
Now right-click TestClass1 in Package Explorer, and then select Run As and FlexUnit Tests. /b12> You'll see the following output in the Flash Builder test window.
Flash Builder also displays test results in the browser.