Continuous Integration with Flex – Part 2

In the next step to CI Nirvana, I’m going to be looking at using ANT to build both our testHarness and the main mxml file. As I mentioned in my previous post, the job we need ANT to do is get it to compile the testHarness, wait for it to close, then compile your main build.

You can use ANT to compile flex using the mxmlc compiler. Create a build.xml file at the top level of your project and paste the following in there:

<?xml version="1.0"?>
<project name="myProject" basedir="." default="all">
<property file="build.properties" />
<target name="all" depends="runTestHarness,compileMain"/>
<target name="properties">
	<fail unless="mxmlc.dir">The "mxmlc.dir" property must be set in
	${basedir}/build.properties.</fail>
	<fail unless="flash.debugPlayer">The "flash.player" property must be set in
	${basedir}/build.properties.</fail>
	<fail unless="main.mxml.source">The "savings.mxml.source" property must be set in
	${basedir}/build.properties.</fail>
</target>
<target name="compileUnitTests" depends="properties">
	<exec executable="${mxmlc.dir}/mxmlc.exe" dir="${mxmlc.dir}">
		<arg line="-aspath '${basedir}/${src.path}';'${asunit.dir}'"/>
		<arg line="-o '${basedir}${outputdir}${testBuildDir}${testHarness.name}.swf'"/>
		<arg line="-configuration '${basedir}/flex-config.xml'"/>
		<arg line="'${basedir}/${testHarness.name}.mxml'"/>
	</exec>
</target>
<target name="runTestHarness" depends="compileUnitTests">
	<exec executable="${basedir}${flash.debugPlayer}" spawn="no" >
		<arg line="'${basedir}${outputdir}${testBuildDir}${testHarness.name}.swf'"/>
	</exec>
</target>
<target name="compileMain">
	<exec executable="${mxmlc.dir}/mxmlc.exe" dir="${mxmlc.dir}">
		<arg line="-aspath '${basedir}/${src.path}';'${asunit.dir}'"/>
		<arg line="-configuration '${basedir}/flex-config.xml'"/>
		<arg line="-o '${basedir}/${outputdir}/${buildDir}/${main.swf.name}.swf'"/>
		<arg line="'${basedir}/${main.mxml.source}.mxml'"/>
	</exec>
</target>

Your build properties file should look something like this:

# ------------------------
# file names
# ------------------------
main.mxml.source=main
testHarness.name=testHarness
main.swf.name=main
# ------------------------
# paths
# ------------------------
lib.dir=lib
outputdir=bin
mxmlc.dir = C:/Program Files/Macromedia/Flex/bin
flash.debugPlayer=${lib.dir}/SAFlashPlayer.exe
src.path = src
asunit.dir = #PATH_TO_ASUNIT
testBuildDir = testFiles
mainBuildDir = main

A few notes on our build script:

  • We put a copy of the flash debug player in the lib folder of our project. This means that when we move the project to another machine (or running on the server…) we don’t need to worry about finding the absolute path to our debug player.
  • Our project outputs go in the bin directory. Test output goes in a subdirectory called testFiles, and main output goes in one called, erm ‘main’ . The reason we built it this way is that when developing our webservices are not always ready when we need them, so our main app is set up to run off mock objects, which are also shared by the test harness. These are in a folder in bin cryptically called mockObjects. Later down the process, it’ll become clear why we have all this stuff in the bin directory…
  • As you can see, we specify the path to the asunit directory, as this is not part of our current project. If you have other classpaths you want to add, you can just add them to the –aspath argument of the compiles.

So, if you now run your ant build, you should see your test harness run , then close after a while, and then your main build compiles. So far, so good, but it’s not really rocking yet; what we now need to do is get our ANT build to know if our unit tests have actually passed or not. In order to do this, we will need to get ANT to understand the result of the unit tests, and this is what we will look at next…

This entry was posted in Continuous Integration, Flash & Actionscript. Bookmark the permalink. Comments are closed, but you can leave a trackback: Trackback URL.