3)ant的build文件D:Banyanhellosrcexampleuild.xml
其內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8" ?>
<project name="HelloWorld" default="junit" basedir=".">
<property name="src" value="."/>
<property name="dest" value="."/>
<property name="report" value="."/>
<target name="init">
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}"/>
</target>
<target name ="junit" depends ="compile">
<tstamp/>
<junit printsummary ="true">
<formatter type ="xml"/>
<test name="HelloWorldTest" todir="."></test>
</junit>
<junitreport todir=".">
<fileset dir=".">
<include name="*.xml"/>
</fileset>
<report format="frames" todir="."/>
</junitreport>
</target>
</project>
4)在命令行切換到該目錄 (cd /d D:Banyanhellosrcexample)后,輸入
ant,有如下內(nèi)容:
D:Banyanhellosrcexample>ant
Buildfile: D:Banyanhellosrcexampleuild.xml
init:
compile:
[javac] D:Banyanhellosrcexampleuild.xml:9: warning: 'includeantruntime
' was not set, defaulting to build.sysclasspath=last; set to false for repeatabl
e builds
[javac] Compiling 1 source file to D:Banyanhellosrcexample
junit:
[junit] Running HelloWorldTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.266 sec
[junitreport] the file D:BanyanhellosrcexampleTESTS-TestSuites.xml is not a
valid testsuite XML document
[junitreport] the file D:Banyanhellosrcexampleuild.xml is not a valid test
suite XML document
[junitreport] Processing D:BanyanhellosrcexampleTESTS-TestSuites.xml to C:
DOCUME~1kortideLOCALS~1Temp
ull281622628
[junitreport] Loading stylesheet jar:file:/F:/apache-ant-1.8.1/lib/ant-junit.jar
!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform. time: 1829ms
[junitreport] Deleting: C:DOCUME~1kortideLOCALS~1Temp
ull281622628
BUILD SUCCESSFUL
Total time: 6 seconds
5)也可以不用ant,直接用junit測(cè)試,過(guò)程如下,切換到該目錄(cd /d D:Banyanhellosrcexample)后,編譯軟程序,直接測(cè)試。
javac HelloWorld.java
javac HelloWorldTest.java
執(zhí)行后,在D:Banyanhellosrcexample下會(huì)出現(xiàn)HelloWorld.class 和HelloWorldTest.class文件,然后再在命令行里輸入
java org.junit.runner.JUnitCore HelloWorldTest ,出現(xiàn)如下字符
JUnit version 4.8.2
.
Time: 0.016
OK (1 test)
測(cè)試完成。