FlexUnit test environment
The FlexUnit test environment allows you to generate and edit
repeatable tests that can be run from scripts or directly within
Flash Builder. Flash Builder supports both FlexUnit 4 and Flex Unit
1 open source frameworks.
From Flash Builder, you can do the following:
Create unit test cases and unit test suites
Flash
Builder wizards guide you through the creation of test cases and
test suites, generating stub code for the tests.
Run the test cases and test suites
You can run test
cases and test suites various ways from within Flash Builder or outside
the Flash Builder environment. The results of the tests are displayed
in a test application. Flash Builder opens a Flex Unit Results View
for analysis of the test run.
Navigate to source code from the Flex Unit Results View
In
the Test Results panel, double-click a test to open the test implementation.
The
Test Failure Details panel lists the source and line number of the
failure. If the listed source is in the current workspace, double-click
the source to go directly to the failure.
Creating FlexUnit testsYou can create FlexUnit test case classes and test case
suites for the following types of projects:
Flex project
ActionScript project
Flex Library project
AIR project
When creating a test case class, you can specify the following
options:
A FlexUnit test case suite is a series of tests based on previously
created test case classes, specified methods in those classes, and
other test case suites.
Creating a FlexUnit test case classWhen you create a FlexUnit test case class, Flash Builder
generates an ActionScript file for the test case class, which it
places in a package for test cases.
The following procedure assumes that you have created a project
in Flash Builder in which you want to create and run Flex Unit tests.
Select the Flex project and then from the context menu,
select New > Test Case Class.
If you select an ActionScript
class file in project, then that class is automatically selected
for the FlexUnit test case in the New Test Case Class wizard.
In the New Test Case Class wizard, specify whether to create
a class in the FlexUnit 4 style or FlexUnit 1 style.
Specify a name for the test case class.
(Optional) Specify a source folder and package for the test
case class, or accept the defaults.
The default source folder
is the src folder of the current project. The default package
is flexUnitTests, which is at the top level of
the default package structure for the project.
(Optional) Enable the Select Class to Test toggle, and browse
to a specific class. Click Next.
(Optional) Select the methods in the selected class that
you want to test.
Click Finish.
Code the test case you created. Use the
generated code stubs as a starting point.
Creating a FlexUnit test case suiteThis procedure assumes that you have previously created
test case classes.
Select the Flex project and then create a test case suite
from the context menus by selecting New > Test Suite Class.
In the New Test Suite Class wizard, specify whether to create
a class in the FlexUnit 4 style or FlexUnit 1 style.
Provide a name for the test suite.
Navigate in the test suites and test cases to select the
classes and methods to include in the test suite. Click Finish.
Customizing default FlexUnit test case classes and test case suite classesYou can customize the default FlexUnit test case classes
and test case suite classes that are created by Flash Builder. Flash
Builder uses file templates to create the default versions of these
files.
The file templates for FlexUnit are available from the Preferences
window at Flash builder > File Templates > FlexUnit. There
are separate templates for FlexUnit1 and FlexUnit4 test case classes
and test suite classes.
See Customizing File Templates for information on how to modify the default
file templates.
Note: FlexUnitCompilerApplication.mxml and FlexUnitApplication.mxml derive
from the template for MXML Web Application or MXML Desktop Application.
The template that is used depends on whether the Flex project is
configured for a web application (runs in Adobe® Flash® Player) or a desktop application (runs
in Adobe AIR®).
Running FlexUnit testsFlexUnit tests can be run from within Flash Builder or
from outside Flash Builder using SWFs generated for the FlexUnit
test. In either case, the results of the tests are displayed in
the FlexUnit Results View.
You can also configure and save a FlexUnit test before running
it.
By default, FlexUnit tests run in the Flash Debug perspective.
You can launch tests from the Flash Development or Flash Profile
perspectives, but Flash Builder switches to the Flash Debug perspective
when running the test.
You can modify the default perspective for FlexUnit tests. Open
the Preferences window, and navigate to Flash Builder > FlexUnit.
FlexUnit compiler application and FlexUnit applicationWhen you create a FlexUnit test case, Flash Builder creates
the following FlexUnit compiler application and a FlexUnit application:
Flash Builder uses these applications when compiling and running
FlexUnit tests. Flash Builder places the applications, in the src directory
of the project.
This application contains references to all FlexUnit test cases
and test suites generated by Flash Builder. Flash Builder places
all FlexUnit tests in the <fx:Declarations> tag
of this application. You typically do not edit or modify this file
directly.
Refresh the FlexUnit compiler application for the following circumstances:
You manually add a test case.
If you create a test
case class without using the New Test Case wizard, refresh FlexUnitCompilerApplication.mxml.
Place the new test case in the package with the other test cases.
You rename a test case
You delete a test case
Refresh FlexUnitCompilerApplication.mxml:
If the FlexUnit Results view is not open, select Windows
> Other Views > FlexUnit Results. Click OK.
In the FlexUnit Results view, click the Refresh button.
Run a FlexUnit test within Flash BuilderYou can run FlexUnit tests within Flash Builder on a project
level or for individual test cases.
You typically run FlexUnit tests from the context menu for a
project or from the context menus for an individual test case.
However, you can also run FlexUnit tests from the Flash Builder
Run menu, the Flash Builder Run button, or from the Execute FlexUnit
Test button in the FlexUnit Results view.
If you run tests from the Flash Builder Run menu, a Test Configuration
dialog opens, allowing you to select which test classes and methods
to run. Test cases for library projects cannot be run using the
Flash Builder Run menu.
Flash Builder provides the following keyboard shortcuts to quickly
launch FlexUnit tests:
Run FlexUnit tests from the current selection in the editor.
(See Configuring FlexUnit tests.
Select a project and run the test:
From the context
menu for a project, select Execute FlexUnit Tests.
From the
Flash Builder Run menu or Run button, select Run > FlexUnit Tests.
(Flash Builder Run menu) In the Run FlexUnit Tests configuration
dialog, select the test cases and methods to run in the test. Click
OK to run the tests.
View the test results.
Flash Builder generates a SWF
file in the bin-debug folder of the project.
An application
opens displaying information about the test and indicates when the
test is complete.
The FlexUnit Results View panel opens displaying
the results of the test. See Viewing results of a FlexUnit test run.
Run individual FlexUnit tests:
In the Project Explorer, navigate to the flexUnitTest package:
From
the context menu for a FlexUnit test file, select Execute FlexUnit
Tests.
View the test results.
Flash Builder generates a SWF
file in the bin-debug folder of the project.
An application
opens displaying information about the test and indicates when the
test is complete.
The FlexUnit Results View panel opens displaying
the results of the test. See Viewing results of a FlexUnit test run.
Run a FlexUnit test outside the Flash Builder environmentThis procedure assumes that you have previously run a FlexUnit
test within Flash Builder and that Flash Builder is running.
Copy the generated SWF file for a test from the bin-debug
folder in your project to a folder outside your development environment.
You
can copy the automatically generated SWF file or a SWF file from
a FlexUnit test that you have previously saved and configured.
Run the copy of the SWF file.
Flash Player opens displaying
information about the test and indicates when the test is complete.
The
FlexUnit Results View panel opens in Flash Builder displaying the
results of the test.
Configuring FlexUnit testsOpen the Run FlexUnit Tests configuration dialog:
You
can open the Run FlexUnit Tests configuration dialog from the Run
menu or from the FlexUnit Results view.
Select a project.
From the Flash Builder menu, select Run > Run > Execute FlexUnit
Test.
From the FlexUnit Results view, select the Execute FlexUnit
Tests button.
If the FlexUnit Results view is not open, select
Window > Other Views > Flash Builder > FlexUnit Results.
In the Test Configuration dialog, select the test cases and
methods to save as a test configuration.
Note: The Test Configuration
dialog is not available when you run a test from the context menu
in the Package Explorer.
(Optional) Select Load to import previous configurations
saved as XML files.
Click Save.
Flash Builder writes an XML file and an
MXML file in the .FlexUnitSettings folder of your
project.
You can use the XML file in build scripts to execute
the test.
You can generate a SWF file from the MXML file.
This SWF file can be used for testing outside the Flash Builder
environment. Typically, you copy the generated MXML file to the src folder
in your project to generate the SWF file.
Viewing results of a FlexUnit test runThe FlexUnit Results view displays results of a FlexUnit
test, detailing any failures. You can navigate through the results,
filter the display, write the results to a file, and load the results
from a file.
You can also rerun tests, cancel a running test, and clear the
results from the view.
If the FlexUnit Results view is not open, select Window >
Other Views > Flash Builder > FlexUnit Results.
Test Results PanelThis panel lists all tests within the test run, indicating
whether the test passed or failed.
Double-click a test in the list to go to the test in the ActionScript
editor.
Test Failure Details PanelSelect a test in the Test Results panel to display failure
details.
Each failure detail lists the source file and method, including
the line number of the failure.
If the source file is local to the working space, double-click
the listing to go to the failure in the ActionScript editor.
FlexUnit Results view menuFrom the FlexUnit Results view menu, you can do the following:
Filter the results displayed
Hide the Test Failure
Details panel.
Display only test runs that failed.
Scroll through the test runs displayed in the Test Results
panel.
Cancel a running test.
Save the results of a test run or the configuration of a
test run.
Load results previously saved to a file.
Clear the results from the panel.
Rerun the current test. You can choose from:
Run all tests.
Run failures only.
Run the selected test.
Refresh the FlexUnit configuration.
If you modify a
test or add or remove tests, click refresh to load the new FlexUnit
configuration.
Configure and run FlexUnit tests.
Use the Execute FlexUnit
Tests button to configure and run FlexUnit tests.
|
|