<mkdir dir=\"${build.dir}/lib\"/>
<jar destfile=\"${build.dir}/lib/src.jar\"
basedir=\"${build.dir}\"></jar>
</target>
<target name=\"compiletests\" depends=\"jar\">
<mkdir dir=\"${build.test.dir}\"/>
<javac srcdir=\"${test.dir}\"
destdir=\"${build.test.dir}\"
debug=\"on\">
<classpath>
<pathelement location=\"${src.dir}\"/>
<pathelement location=\"${build.dir}\"/>
</classpath>
</javac>
</target>
<target name=\"runtest\" depends=\"compiletests\" if=\"junit.present\">
<java fork=\"yes\" classname=\"junit.textui.TestRunner\" taskname=\"junit\">
<arg value=\"src.test.TestHello\"/>
<classpath>
<pathelement location=\"lib/junit-4.4.jar\"/>
<pathelement location=\"${test.dir}\"/> <pathelement location=\"${build.dir}\"/>
<pathelement location=\"${build.test.dir}\"/>
<pathelement location=\"${java.class.path}\"/>
</classpath>
</java>
</target>
</project>
解释一下runtest 任务的内容:
使用java命令运行junit.textui.TestRunner,并给该类传一个参数----我的测试类 TestHello.java , 把测试需要的类路径加上...嘿嘿,就OK啦...
贴上TestRunner的核心部分:
public class TestRunner extends BaseTestRunner ...{
private ResultPrinter fPrinter;
public static final int SUCCESS_EXIT= 0;
public static final int FAILURE_EXIT= 1;
public static final int EXCEPTION_EXIT= 2;
//.....此处省略100行.....
/** *//**
* Starts a test run. Analyzes the command line arguments and runs the given
* test suite 运行所给的test suite
*/
public TestResult start(String args[]) throws Exception ...{
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/