Sunday, August 17, 2008

Getting started with Flex unit

Flex unit is a unit testing framework for flex and action script 3.0 applications and libraries. It copies the functionality of J unit, a Java testing framework and comes with a graphical test runner. If you're a java programmer you may be familiar with J Unit. Today, software testing is becoming more important and a good platform needs good testing tools. Now, Adobe releases the unit test tool on flex named Flex Unit. Flex unit is also a hit tool amongst software development tools in South Africa.

To understand unit testing you must first understand what a unit is. A unit is the smallest piece of code that performs a specific task. In Flex this means a function since flex script is an object oriented language. The developer tests code at a low level to make sure each method is performing as expected.

To get started with Flex unit you need to follow few necessary steps. This may not be as exciting to read but they are useful terms.

* Download Flex Unit and include the library:
After you extract the file from the zip, you will find a flexunit.swc in the bin directory. You need to add this library to your project. If you are creating a new project you can specify libraries as part of the project creation. The process is simpler for Flex 3 users. Once you have downloaded the flexunit.swc you simply copy it into the library directory of your project.
* Create unit tests:
A test case is the smallest unit of testing. It checks for a specific response to a particular set of inputs. In some frameworks, all test methods should begin with the word test. A unit test is made up of logical claims. If the claim is true, the unit test passes. If the claim is false then the unit test fails.
* Create a test suite:
As more and more unit tests are built up for a given project, you'll want to group them. Running them one at a time would be troublesome. A test suite can contain other test suites, or individual tests, and is a way of declaring which test must be run in the same session, regardless of whether or not they are in the same file. This is very handy.
* Create a test runner:
A test runner is a component that often has a graphical interface and displays the outcome of our tests. In Flex Unit you tell your test runner which test suite you want to use, and then call its start test method.
Flex Unit provides an automated way to test code at a low level. I think Flex Unit can be used for stress testing as it is not that difficult. Just add multiple test runners for each client application and run all of them.

No comments: