Introduction
There is SDK-wide support for FlexUnit tests, and each project maintains its own set of tests. It currently works like this:
- The main build script (
build.xml
) has a target called 'test
'. This target is not part of the 'main
' run. It simply calls: - The '
test
' target inframeworks/build.xml
, which cleans the previous test reports and calls any test targets that may exist (e.g. 'apache-test
'), which in turn call: - The '
test
' target of that project's build script, which sets up the project-specific properties (such as project root folder) and calls back to: - '
flexunit-tests.xml
' in the SDK root.
This file is where the magic happens. Based on the input from the project build script (step 3 above), it runs any FlexUnit tests that have been set up for that project and reports back their successes or failures.
How to add the first unit tests to a project without tests
Any project for which we want to add FlexUnit tests can easily hook into this system. First, write your tests. Then:
1. Add the tests to the SDK project
If it does not yet exist, create a 'tests/[somePackage]
' directory in the root directory of the project (meaning it will be on the same level with the 'src
' directory), e.g.:
Create test classes in this directory or in a subdirectory thereof; make sure to use file names that match '*Tests.as', e.g.:
'PromisesBasicTests.as' or 'FLEX_34625_Tests.as'
2. Add test run to SDK build scripts
If they do not yet exist, add the following tasks and calls to the following ant files, replacing '[project
]' with the name of the project, e.g. 'apache
' or 'spark
':
./frameworks/build.xml
In the target 'test
', add the call:
<antcall target="[project]-test"/>
Add a target (near the bottom of the file):
<target name="[project]-test" description="Tests for '[project]' project"> <ant dir="${basedir}/projects/[project]" target="test"/> </target>
./framework/projects/[project]/build.xml
Add a target:
<target name="test" description="Runs the FlexUnit tests for this project"> <ant antfile="${FLEX_HOME}/flexunit-tests.xml"> <property name="project.root" value="${basedir}"/> </ant> </target>