为什么 "ant junit" 找不到测试套件
Why does "ant junit" not find the testsuite
当 运行 junit-4.12 测试用例通过 ant -d 启用 XML 报告时,我的测试套件未执行。
这是 build.xml 的一部分:
<target name="compile" depends="prepare">
<!-- kompilieren der Quelldateien -->
<javac includeantruntime="false" srcdir="${source.dir}" destdir="${build.dir}">
<classpath>
<path refid="classPath"/>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
</classpath>
</javac>
<javac includeantruntime="false" srcdir="${tests.dir}" destdir="${build.dir}">
<classpath>
<path refid="classPath"/>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
</classpath>
</javac>
<!-- kopieren der Dateien, die in den
resources-Verzeichnissen liegen -->
<copy todir="${build.dir}" overwrite="y">
<fileset dir="${source.dir}">
<!-- beruecksichtigt alle Verzeichnisse mit
Namen resources und alle .properties Dateien -->
<include name="**/resources/" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<target name="junit" depends="compile">
<junit printsummary="yes" fork="false" haltonfailure="false"
failureproperty="tests.failed" showoutput="true" dir="${build.dir}">
<classpath>
<path refid="classPath" />
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
<!-- <path location="${source.dir}" /> -->
</classpath>
<formatter type="xml" />
<batchtest todir="${report.dir}">
<fileset dir="test">
<exclude name="**/GMRTest*.class" />
<include name="**/AllTests.class" />
</fileset>
</batchtest>
</junit>
</target>
提前致谢!
格瑞特
P. S. 这是我的 JUnit 测试套件 test/AllTests.java:
package test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import projekt.GMR;
@RunWith(Suite.class)
@SuiteClasses({ GMRTest.class,
GMRTest2.class,
GMRTest3.class})
public class AllTests {
@BeforeClass
public static void setUpClass() {
System.out.println("Master setup");
}
@AfterClass public static void tearDownClass() {
System.out.println("Master tearDown");
}
}
我必须在 srcdir + package name = projekt dir
中编译
而不是 srcdir = projekt dir
并在 dir + package name = test dir
中测试
而不是 dir = test dir
所以 dir
和 srcdir
都等于 build.xml
中的 .
当 运行 junit-4.12 测试用例通过 ant -d 启用 XML 报告时,我的测试套件未执行。
这是 build.xml 的一部分:
<target name="compile" depends="prepare">
<!-- kompilieren der Quelldateien -->
<javac includeantruntime="false" srcdir="${source.dir}" destdir="${build.dir}">
<classpath>
<path refid="classPath"/>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
</classpath>
</javac>
<javac includeantruntime="false" srcdir="${tests.dir}" destdir="${build.dir}">
<classpath>
<path refid="classPath"/>
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
</classpath>
</javac>
<!-- kopieren der Dateien, die in den
resources-Verzeichnissen liegen -->
<copy todir="${build.dir}" overwrite="y">
<fileset dir="${source.dir}">
<!-- beruecksichtigt alle Verzeichnisse mit
Namen resources und alle .properties Dateien -->
<include name="**/resources/" />
<include name="**/*.properties" />
</fileset>
</copy>
</target>
<target name="junit" depends="compile">
<junit printsummary="yes" fork="false" haltonfailure="false"
failureproperty="tests.failed" showoutput="true" dir="${build.dir}">
<classpath>
<path refid="classPath" />
<pathelement location="${lib.dir}/junit-4.12.jar" />
<pathelement location="${lib.dir}/hamcrest-all-1.3.jar" />
<pathelement location="test" />
<pathelement location="." />
<!-- <path location="${source.dir}" /> -->
</classpath>
<formatter type="xml" />
<batchtest todir="${report.dir}">
<fileset dir="test">
<exclude name="**/GMRTest*.class" />
<include name="**/AllTests.class" />
</fileset>
</batchtest>
</junit>
</target>
提前致谢!
格瑞特
P. S. 这是我的 JUnit 测试套件 test/AllTests.java:
package test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
import projekt.GMR;
@RunWith(Suite.class)
@SuiteClasses({ GMRTest.class,
GMRTest2.class,
GMRTest3.class})
public class AllTests {
@BeforeClass
public static void setUpClass() {
System.out.println("Master setup");
}
@AfterClass public static void tearDownClass() {
System.out.println("Master tearDown");
}
}
我必须在 srcdir + package name = projekt dir
中编译
而不是 srcdir = projekt dir
并在 dir + package name = test dir
中测试
而不是 dir = test dir
所以 dir
和 srcdir
都等于 build.xml
.