3)ant的build文件D:Banyanhellosrcexampleuild.xml
其内容如下:
<?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,有如下内容:
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测试,过程如下,切换到该目录(cd /d D:Banyanhellosrcexample)后,编译软程序,直接测试。
javac HelloWorld.java
javac HelloWorldTest.java
执行后,在D:Banyanhellosrcexample下会出现HelloWorld.class 和HelloWorldTest.class文件,然后再在命令行里输入
java org.junit.runner.JUnitCore HelloWorldTest ,出现如下字符
JUnit version 4.8.2
.
Time: 0.016
OK (1 test)
测试完成。