锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鑰屼笖榪欐槸涓涓豢鑹茶蔣浠訛紝涓嶉渶瑕佷換浣曠殑瀹夎錛屽弻鍑籩xe鏂囦歡榪愯鍗沖彲銆傚嵏杞芥椂鍙渶瑕佹妸exe鍜宑fg鏂囦歡鍒犻櫎鍗沖彲銆?nbsp; 闃呰鍏ㄦ枃
]]><project name="autobuildtest" default="test">
<target name="setProperties">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
</target>
<target name="prepareDir" depends="setProperties">
<delete dir="${classes.dir}"/>
<mkdir dir="${classes.dir}"/>
</target>
<target name="compile" depends="prepareDir">
<javac srcdir="./src" destdir="${classes.dir}"/>
</target>
<target name="test" depends="compile">
<junit printsummary="yes">
<test name="onlyfun.caterpillar.test.MathToolTest"/>
<classpath>
<pathelement location="${classes.dir}"/>
</classpath>
</junit>
</target>
</project>
涓婇潰XML鏂囦歡楂樹寒澶勬弿榪頒簡Ant濡備綍涓嶫Unit緇撳悎榪涜鑷姩鍖栨祴璇曪紝name灞炴ф槸浣犺嫻嬭瘯鐨凾estCase錛宑lasspath鍏冪礌鎸囨槑浜員estCase鐨勮礬寰勶紝printsummary璇存槑浜嗚灝嗘祴璇曠殑緇撴灉綆鍗曠殑鏄劇ず鍑烘潵銆?br style="font-family: " />
濡備綍鍚Unit嫻嬭瘯鐨勮緇嗕俊鎭樉紺哄嚭鏉ュ憿錛熸垜浠彲浠ラ噰鐢?lt;formatter>鍏冪礌錛屽涓嬫墍紺猴細
<junit printsummary="yes">
<formatter type="plain" usefile="false"/>
<test name="onlyfun.caterpillar.test.MathToolTest"/>
<classpath>
<pathelement location="${classes.dir}"/>
</classpath>
</junit>
褰搖sefile灞炴ц瀹氫負true鏃訛紝浼氳嚜鍔ㄥ府鎮ㄥ皢浜х敓鐨勭粨鏋滃偍瀛樺湪妗f涓紝棰勮鏄疶EST-*.txt錛屽叾涓?鏄偍鐨勬祴璇曟渚嬬被鍒悕縐般傞櫎姝や箣澶栵紝鎴戜滑涔熷彲鐢ㄩ噰鐢╔ML鐨勬牸寮忔潵淇濆瓨嫻嬭瘯緇撴灉銆傚涓嬫墍紺猴細
<formatter type="xml"/>
涔熷彲浠ュ皢嫻嬭瘯緇撴灉鎵浜х敓鐨刋ML鏂囦歡杞崲涓篐TML鏂囦歡錛屼嬌鐢ˋnt鍙互鐩存帴甯偍瀹屾垚榪欎釜宸ヤ綔錛?lt;junitreport>鏍囩浣跨敤 XSLT灝哫ML鏂囦歡杞崲涓篐TML鏂囦歡
<project name="autobuildtest" default="report">
<target name="setProperties">
<property name="src.dir" value="src"/>
<property name="classes.dir" value="classes"/>
<property name="report.dir" value="report"/>
</target>
<target name="prepareDir" depends="setProperties">
<delete dir="${report.dir}"/>
<delete dir="${classes.dir}"/>
<mkdir dir="${report.dir}"/>
<mkdir dir="${classes.dir}"/>
</target>
<target name="compile" depends="prepareDir">
<javac srcdir="./src" destdir="${classes.dir}"/>
</target>
<target name="test" depends="compile">
<junit printsummary="yes">
<formatter type="xml"/>
<test name="onlyfun.caterpillar.test.MathToolTest"
todir="${report.dir}"/>
<classpath>
<pathelement location="${classes.dir}"/>
</classpath>
</junit>
</target>
<target name="report" depends="test">
<junitreport todir="${report.dir}">
<fileset dir="${report.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${report.dir}/html"/>
</junitreport>
</target>
</project>
涓婇潰鐨勪緥瀛愶紝棣栧厛瀹氫箟浜嗕竴涓猵roperty錛岀敤浜庢寚鍚戜繚瀛樻祴璇曠粨鏋滅殑鐩綍錛屾帴鐫鍦?lt;test>鍏冪礌涓氳繃<todir>灝嗙粨鏋滄寚鍚戣鐩綍銆傜劧鍚巖eport鐩爣棣栧厛鍦╰odir灞炴ф寚瀹氱殑鐩綍涓嬫煡鎵懼悕縐板寘鍚細TESTd鐨刋ML鏂囦歡錛屾壘鍒頒箣鍚庨氳繃XSL杞崲鎴愬甫frame鐨凥TML欏甸潰錛屽瓨鏀懼埌瀛愮洰褰昲tml涓嬮潰
鏈緇堢殑緇撴灉鍙兘濡備笅錛?br />
]]>
<classpath>
<pathelement path="${classpath}"/>
<pathelement location="lib/helper.jar"/>
</classpath>
鍘熸枃錛歍he location attribute specifies a single file or directory relative to the project's base directory (or an absolute filename), while the path attribute accepts colon- or semicolon-separated lists of locations. The path attribute is intended to be used with predefined paths - in any other case, multiple
elements with location attributes should be preferred.
浠庝腑鎴戜滑鍙互鐪嬪嚭path鍙互鐢ㄤ簬鎸囧悜瀛樺湪澶氫釜鏂囦歡鐨勪綅緗紝鑰宭ocation鍙兘鎸囧悜鍗曚釜鐨勬枃浠舵垨鐩綍銆傚彟澶杙ath鍙互琚瀹歩d錛屼緵鍏跺畠鐨刾ath鎴朿lasspath寮曠敤銆傚錛?lt;path id="main-classpath">錛岃宑lasspath鍒欐病鏈?/span>
銆?銆戠患鍚堢ず渚嬶細
In addition, DirSets, FileSets, and FileLists can be specified via nested <dirset>, <fileset>, and <filelist> elements, respectively. Note: The order in which the files building up a FileSet are added to the path-like structure is not defined.
<classpath>
<pathelement path="${classpath}"/> 鏂瑰紡鈶?錛氬紩鐢ㄧ壒瀹氱殑鍙橀噺
<fileset dir="lib"> 鏂瑰紡鈶?錛氭寚鍚戠壒瀹氱殑鏂囦歡闆?/strong>
<include name="**/*.jar"/>
</fileset>
<pathelement location="classes"/> 鏂瑰紡鈶細鎸囧悜鍗曚釜鐩綍
<dirset dir="${build.dir}"> 鏂瑰紡鈶o細鎸囧悜鐗瑰畾鐩綍闆?/strong>
<include name="apps/**/classes"/>
<exclude name="apps/**/*Test*"/>
</dirset>
<filelist refid="third-party_jars"/> 鏂瑰紡鈶わ細寮曠敤鎸囧畾鏂囦歡鍒楄〃
</classpath>
This builds a path that holds the value of ${classpath}, followed by all jar files in the lib directory, the classes directory, all directories named classes under the apps subdirectory of ${build.dir}, except those that have the text Test in their name, and the files specified in the referenced FileList.