Skip to content

Instantly share code, notes, and snippets.

@yangboz
Created January 21, 2014 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangboz/8534035 to your computer and use it in GitHub Desktop.
Save yangboz/8534035 to your computer and use it in GitHub Desktop.
Ant xml example(AIRAntJUnitTestClover) for FLEX/AS3 code j-unit test with colver reporting.
<?xml version="1.0"?>
<project name="AIRAntUnitTest" default="build">
<!-- TODO Change to your Flex SDK directory -->
<property name="flex.sdk.dir" value="C:\Software\FLEX\sdks\4.6.0" />
<property name="lib.dir" value="${basedir}/libs" />
<property name="src.dir" value="${basedir}/src" />
<!-- ATTENTION: Since we remove the reports directory during the clean target it get's
deleted so DO NOT specifiy any directory which you do not want to be deleted!!! -->
<property name="output.loc" location="${basedir}/target" />
<property name="bin.loc" location="${output.loc}/unittest/bin" />
<property name="report.loc" location="${output.loc}/unittest/report" />
<property name="dist.loc" location="${output.loc}/unittest/dist" />
<property name="reports.dir" value="${output.loc}/unittest/report" />
<property name="APP_NAME" value="AIRAntUnitTest"/>
<property name="FLEX_HOME" value="${flex.sdk.dir}" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<!-- Adding Clover task definitions -->
<property name="clover.lib.dir" location="${lib.dir}/clover"/>
<property name="clover.jar" location="${lib.dir}/clover/clover.jar"/>
<property name="clover.license" location="${lib.dir}/clover/clover.license"/>
<property name="clover.db.file" location="${output.loc}/clover/clover3_2_0.db"/>
<taskdef resource="cloverlib.xml" classpath="${clover.jar}"/>
<property name="clover.reports.dir" value="${output.loc}/clover/report" />
<property name="clover.tmp.dir" location="${output.loc}/clover/tmp"/>
<property name="clover.classes.dir" location="${output.loc}/clover/classes"/>
<!-- Define ADL (AIR Debug Launcher) cross platform -->
<condition property="ADL" value="${FLEX_HOME}/bin/adl.exe">
<os family="windows"/>
</condition>
<property name="ADL" location="${FLEX_HOME}/bin/adl" />
<property name="AIR_OUTPUT" value="bin-release"/>
<property name="APP_DESCRIPTOR" value="${AIR_OUTPUT}/${APP_NAME}-app.xml"/>
<target name="build" depends="clean, compile, run-tests, generate-reports,clover.report" />
<target name="clean">
<delete dir="${AIR_OUTPUT}" />
<delete dir="${reports.dir}" />
<!-- Adding <clover-clean> to the Clean Target -->
<clover-clean/>
</target>
<target name="compile">
<mxmlc file="${basedir}/src/${APP_NAME}.mxml"
locale="en_US"
debug="true"
configname="air"
output="${AIR_OUTPUT}/${APP_NAME}.swf"
actionscript-file-encoding="UTF-8">
<source-path path-element="${basedir}/src" />
<!-- Core Flex Libraries -->
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
</compiler.library-path>
<compiler.library-path dir="${FLEX_HOME}/frameworks/locale" append="true">
<include name="en_US" />
</compiler.library-path>
<!-- Local Libraries (FlexUnit.swc) -->
<compiler.library-path dir="${basedir}" append="true">
<include name="libs" />
<include name="libs/junit" />
</compiler.library-path>
</mxmlc>
</target>
<target name="run-tests">
<delete dir="${reports.dir}" />
<mkdir dir="${reports.dir}"/>
<echo>Test descriptor ${APP_DESCRIPTOR} with ADL ${ADL} and content ${APP_NAME}.swf</echo>
<!-- If you have a FlexBuilder generated application descriptior you have
to replace the token below manually to set the right APPLICATION.swf -->
<copy file="${basedir}/src/${APP_NAME}-app.xml" todir="${basedir}/${AIR_OUTPUT}" overwrite="true" />
<replace file="${APP_DESCRIPTOR}"
token="[This value will be overwritten by Flex Builder in the output app.xml]"
value="${APP_NAME}.swf" />
<!-- Run the tests -->
<exec executable="${ADL}" failonerror="false">
<arg line="${APP_DESCRIPTOR}"/>
<arg line="-- '${reports.dir}'"/>
</exec>
</target>
<target name="generate-reports">
<echo>Generate reports to ${reports.dir}</echo>
<junitreport todir="${reports.dir}">
<fileset dir="${reports.dir}">
<include name="*_TEST-*.xml"/>
</fileset>
<report format="frames" todir="${reports.dir}/html"/>
</junitreport>
</target>
<!-- Adding Clover target -->
<target name="with.clover">
<delete file="${clover.db.file}"/>
<clover-instr initstring="${clover.db.file}" srcdir="${src.dir}" destdir="${clover.tmp.dir}"></clover-instr>
<clover-setup initString="${clover.db.file}" preserve="true"/>
</target>
<!-- Adding Clover compliler if needed -->
<target name="clover.compile" depends="with.clover">
<javac
srcdir="${clover.tmp.dir}"
destdir="${clover.classes.dir}"
encoding="UTF-8"
includeantruntime="true"
failonerror="true"
verbose="false"
compiler="modern"
fork="true"
target="1.7"
nowarn="true">
<classpath refid="build.lib"/>
</javac>
</target>
<!-- Adding Clover to the build classpath -->
<path id="build.classpath">
<pathelement path="${clover.jar}"/>
</path>
<!-- Adding a Clover report target -->
<target name="clover.report" depends="clover.compile">
<clover-html-report outdir="${clover.reports.dir}" testresultsdir="${reports.dir}/html" title="Clover Report"/>
</target>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment