We are a user experience design and software development firm
Hire us to design your site, build your application, serve billions of users and solve real problems.
In most projects, people tend to separate source and test code into separate directories. However, out of the box, FlexUnit with Antennae is geared toward a single directory which contains all source and test code. I didn't really want to mix everything together like this, so I modified Antennae to work with a separated structure. Here is the quick and dirty on getting it to work (assuming you're using FlexUnit .85 and Antennae 1.2.0)
To accomplish this, some changes need to be made to flex-antennae/tools/build-common-targets.xml. I just made the changes directly to the scripts, but it would probably be better to override the targets in question in a separate file (this would make upgrading much easier).
The flex-test-application target builds the application that runs the tests. You will want to add a compiler option to the options attribute in the mxmlc tag which specifies multiple source paths. To keep the following example simple, all the source code is in a single directory and all the test code is in a different directory (no subdirectories). Since the compiler seems to ignore code in subdirectories, you'll just need to add additional paths to the argument in order to support subdirectories.
<target name="flex-test-application"
depends="init,create-test-suite,flex-application-check,flex-application-copy"
unless="${project.tests.swf}.compiled"
description="Compile the application">
<mxmlc src="${build.generated.dir}/${project.flex.application}"
dest="${build.mxmlc.dir}/${project.tests.swf}"
options="-verbose-stacktraces=true ${flex.mxmlc.options} -compiler.source-path ${src.flex.dir} ${test.flex.dir}" />
</target>
You might notice that some of the properties are different from vanilla Antennae. Specifically, I have added properties so that the test SWF file does not have the same name as the application SWF file. Notice how this changes the unless attribute in the target. Properties that define the source and test directories have also been added.
src.flex.dir = src/flex/
test.flex.dir = test/flex/
project.tests.swf = ${project.name}_tests.swf
You'll also need to change the create-test-suite target so that the arg child has a value which points to our test directory instead of the source directory.
<arg value="${test.flex.dir}" />
Similarly, you'll want to change the test-flexunit-mac and test-flexunit-notmac targets so that the arg child points to the test SWF instead of the application SWF.
<arg value="${project.tests.swf}" />
Finally, ensure that the test target depends on the correct targets.
<target name="test" depends="build,flex-test-application,test-flexunit" description="Test the project" />
There are many more tweaks which can be made to improve FlexUnit integration with Antennae (such as better support for running the tests under headless Linux, allowing a main MXML file to have a different name from the project name, allowing custom functions and properties in the main MXML file, etc.), but they are outside the scope of this post.
Topics: actionscript, antennae, Flex, flexunit
Hire us to design your site, build your application, serve billions of users and solve real problems.
I have a problem running the antennae tutorial test example. I’m running on linux and i am getting to the point where the flashplayer starts with the Test.swf. But than the test stops. Could you give me a hint where to look.
Comment by Patrick van Amstel, Friday, June 6, 2008 @ 2:28 am
Sorry for taking so long getting back to you, I was on vacation.
The problem is most likely that you need to specify what display to use when running linux. In order to get our cruise build running on a headless linux server, we needed to specify this. In build.xml, under the “init” target, add the following:
<condition property=”environment.display” value=”:1″>
<os name=”Linux”/>
</condition>
Of course, the value may vary based on your setup.
Hope this helps.
Comment by Anthony Caliendo, Tuesday, July 1, 2008 @ 12:08 pm