在Ant中调用FlexUnit,完成对Flex(AS)代码的测试。
在
http://weblogs.macromedia.com/pmartin/archives/2006/06/flexunit_ant.html中,Peter Martin已经为我们提供了FlexUnit的包以及例子
但是下载下来发现用不了,修改如下:
1. 导入下载的工程
FlexUnitExample,将
FlexAntTasks.jar拷贝到ClassPath中,然后修改build.properties文件,增加basedir=".",修改
flex.unit.swf="${basedir}/bin/AntTestRunner.swf"
basedir="."
# General properties
output.dir=${basedir}/dist
# Compile properties
#flex.sdk.home=C:/apps/adobe/flex2.0/sdk
flex.sdk.home=D:/Dev/Adobe/Flex Builder 3/sdks/3.0.0
application=AntTestRunner.mxml
mxmlc.args=-file-specs ${application} -library-path+=lib -output ${flex.unit.swf}
# Test properties
#flex.unit.swf=${output.dir}/AntTestRunner.swf
flex.unit.swf=${basedir}/bin/AntTestRunner.swf
report.dir=${basedir}/report
2.修改build.xml
<project name="FlexUnitExample" default="main">
<!-- Load the custom task definitions. -->
<taskdef
resource="com/adobe/ac/ant/tasks/tasks.properties" />
<!--
<taskdef
resource="com/adobe/ac/ant/tasks/tasks.properties"
classpath="${basedir}/FlexAntTasks.jar"/>
-->
<!-- Load the properties file. -->
<property file="build.properties" />
<target name="main" depends="compile, test" />
<target name="compile">
<exec
dir="${basedir}"
executable="${flex.sdk.home}/bin/mxmlc.exe"
os="Windows XP"
failonerror="false">
<arg line="${mxmlc.args}" />
</exec>
<exec
dir="${basedir}"
executable="${flex.sdk.home}/bin/mxmlc"
os="Linux"
failonerror="false">
<arg line="${mxmlc.args}" />
</exec>
</target>
<target name="test">
<flexunit
timeout="0"
swf="${flex.unit.swf}"
toDir="${report.dir}"
haltonfailure="false" />
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${report.dir}/html"/>
</junitreport>
</target>
</project>
3. 运行ant,就可以了,还是很方便的。