在构建Ant自动测试的时候,必须要加入ant_home/lib下的库,要不会出现ClassNotFound的异常。
<
path
id
="test.classpath"
>
< fileset dir ="${ant.library.dir}" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${test.home}/classes" />
</ path >
< target name ="test" depends ="all" >
< mkdir dir ="${test.report}" />
< mkdir dir ="${test.home}/classes" />
< javac srcdir ="${test.home}/src"
destdir ="${test.home}/classes"
debug ="${compile.debug}"
deprecation ="${compile.deprecation}"
optimize ="${compile.optimize}" >
< classpath refid ="master-classpath" />
</ javac >
< junit printsummary ="true"
fork ="true"
haltonfailure ="false"
failureproperty ="tests.failed"
showoutput ="true" >
< classpath refid ="test.classpath" />
< classpath refid ="master-classpath" />
< formatter type ="xml" />
< batchtest todir ="${test.report}" >
< fileset dir ="${test.home}/classes" >
< include name ="**/*Test.*" />
</ fileset >
</ batchtest >
</ junit >
< junitreport todir ="${test.report}" >
< fileset dir ="${test.report}" >
< include name ="TEST-*.xml" />
</ fileset >
< report format ="frames" todir ="${test.report}" />
</ junitreport >
< fail if ="tests.failed" >
---------------------------------------------------------
One or more tests failed, check the report for detail...
---------------------------------------------------------
</ fail >
</ target >
< fileset dir ="${ant.library.dir}" >
< include name ="*.jar" />
</ fileset >
< pathelement location ="${test.home}/classes" />
</ path >
< target name ="test" depends ="all" >
< mkdir dir ="${test.report}" />
< mkdir dir ="${test.home}/classes" />
< javac srcdir ="${test.home}/src"
destdir ="${test.home}/classes"
debug ="${compile.debug}"
deprecation ="${compile.deprecation}"
optimize ="${compile.optimize}" >
< classpath refid ="master-classpath" />
</ javac >
< junit printsummary ="true"
fork ="true"
haltonfailure ="false"
failureproperty ="tests.failed"
showoutput ="true" >
< classpath refid ="test.classpath" />
< classpath refid ="master-classpath" />
< formatter type ="xml" />
< batchtest todir ="${test.report}" >
< fileset dir ="${test.home}/classes" >
< include name ="**/*Test.*" />
</ fileset >
</ batchtest >
</ junit >
< junitreport todir ="${test.report}" >
< fileset dir ="${test.report}" >
< include name ="TEST-*.xml" />
</ fileset >
< report format ="frames" todir ="${test.report}" />
</ junitreport >
< fail if ="tests.failed" >
---------------------------------------------------------
One or more tests failed, check the report for detail...
---------------------------------------------------------
</ fail >
</ target >