[英]Run multiple JUnit tests with Ant
probably this is a very basic question but I am new to java, so please bear with me. 可能这是一个非常基本的问题,但是我是java的新手,所以请多多包涵。 I am trying to run java task in ant and I want to know if there is any way to get all the name of the classes inside a folder in ant? 我正在尝试在ant中运行java任务,我想知道是否有任何方法可以在ant的文件夹中获取所有类的名称?
This is the build.xml file 这是build.xml文件
<project default='run-test' basedir=".">
<property name="src" value="src"/>
<property name="test" value="test"/>
<property name="build" value="build"/>
<property name="build-classes" value="build/classes"/>
<property name="build-test-classes" value="build/test/classes"/>
<property name="junit4" value="/usr/share/java/junit4.jar"/>
<target name="init">
<mkdir dir="${build-classes}"/>
<mkdir dir="${build-test-classes}"/>
</target>
<target name="compile" depends="init">
<javac includeantruntime="false"
srcdir="${src}"
destdir="${build-classes}"/>
</target>
<target name="compile-test" depends="compile">
<javac includeantruntime="false"
classpath="${junit4}:${build-classes}"
srcdir="${test}"
destdir="${build-test-classes}"/>
</target>
<target name="run-test" depends="compile-test">
<java classpath="${junit4}:${build-classes}:${build-test-classes}"
classname="org.junit.runner.JUnitCore"
args="myclass.MyClassTest"/> <---This is my problem
</target>
<target name="clean">
<delete dir="${build}"/>
</target>
</project>
I have to manually mention the name of the class in the arguments. 我必须在参数中手动提及类的名称。 Is there any way where I can only mention the folder and all the class names will be taken up as arguments for the javatask automatically? 有什么办法我只能提及该文件夹,并且所有类名都将自动用作javatask的参数?
Ant ships with a task for running JUnit tests . Ant附带了用于运行JUnit测试的任务。
In the run-test
target in your example, replace the <java>
task with the following: 在示例的run-test
目标中,将<java>
任务替换为以下内容:
<junit>
<formatter type="plain" usefile="false"/>
<classpath>
<pathelement location="${junit4}"/>
<pathelement location="${build-classes}"/>
<pathelement location="${build-test-classes}"/>
</classpath>
<batchtest>
<fileset dir="${build-test-classes}">
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.