Ant 测试编译崩溃
Ant Test Compile Crashes
我正在尝试编译一个名为 TestsVorgabe 的 class,它代表一个包含五个其他测试的测试套件。它在正常的 JUnit 测试中工作正常,但是当我尝试用 ant 编译它时,我得到一个
错误:找不到符号
这样的项目结构:
- project/src => 类
- project/test => 测试类
为了确保我真的得到正确的 .jars 并包含它们,我有两种方法将它们传递给 Ant。我的 Ant 构建文件如下所示:
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="dist"/>
<property name="docs.dir" location="docs"/>
<property name="test.dir" location="test"/>
<property name="buildtest.dir" location="buildtest"/>
<path id="src.path">
<pathelement path="src/"/>
</path>
<path id="compile.path">
<path refid="src.path"/>
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="unit.test.path">
<path refid="compile.path"/>
<pathelement path="test/"/>
</path>
<!--Löscht die erstellten Verzeichnisse und Sourcen-->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${buildtest.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${docs.dir}"/>
</target>
<!--Erzstellt die Verzeichnisstruktur-->
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${buildtest.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${docs.dir}"/>
<mkdir dir="${dist.dir}/dist2"/>
</target>
<!--Kompiliert die Programm-Klassen-->
<target name="compile">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="compile.path"/>
</javac>
</target>
<target name="compileUnitTests" depends="compile">
<javac srcdir="test/" destdir="${buildtest.dir}">
<classpath refid="unit.test.path"/>
</javac>
</target>
<target name="runUnitTests" depends="compile">
<junit printsummary="yes" haltonfailure="no">
<jvmarg value="-Dfile.encoding=UTF-8"/>
<classpath refid="unit.test.path"/>
<formatter type="plain"/>
<batchtest fork="yes" todir="${buildtest.dir}">
<fileset dir="${test.dir}">
<include name="**/TestsVorgabe.java"/>
<exclude name="**/AllTests.class"/>
<exclude name="**/*$*.class"/>
</fileset>
</batchtest>
</junit>
</target>
我已经尝试了很多方法来包含 .jars 和很多编译测试的方法,但似乎没有任何效果所以我最终得到了这个(也不起作用)。
您使用 javac 将您的源代码编译到 ${build.dir}
但您没有将其添加到 junit 任务的类路径中,这是 documentation:
中的示例
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${java.class.path}"/>
</classpath>
或检查this example(在示例中:${web.classes.dir}
)。
尝试将 build.dir 添加到 junit 任务类路径,希望对您有所帮助!
我正在尝试编译一个名为 TestsVorgabe 的 class,它代表一个包含五个其他测试的测试套件。它在正常的 JUnit 测试中工作正常,但是当我尝试用 ant 编译它时,我得到一个
错误:找不到符号
这样的项目结构:
- project/src => 类
- project/test => 测试类
为了确保我真的得到正确的 .jars 并包含它们,我有两种方法将它们传递给 Ant。我的 Ant 构建文件如下所示:
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="dist"/>
<property name="docs.dir" location="docs"/>
<property name="test.dir" location="test"/>
<property name="buildtest.dir" location="buildtest"/>
<path id="src.path">
<pathelement path="src/"/>
</path>
<path id="compile.path">
<path refid="src.path"/>
<fileset dir="lib/">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="unit.test.path">
<path refid="compile.path"/>
<pathelement path="test/"/>
</path>
<!--Löscht die erstellten Verzeichnisse und Sourcen-->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${buildtest.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${docs.dir}"/>
</target>
<!--Erzstellt die Verzeichnisstruktur-->
<target name="init">
<mkdir dir="${build.dir}"/>
<mkdir dir="${buildtest.dir}"/>
<mkdir dir="${dist.dir}"/>
<mkdir dir="${docs.dir}"/>
<mkdir dir="${dist.dir}/dist2"/>
</target>
<!--Kompiliert die Programm-Klassen-->
<target name="compile">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="compile.path"/>
</javac>
</target>
<target name="compileUnitTests" depends="compile">
<javac srcdir="test/" destdir="${buildtest.dir}">
<classpath refid="unit.test.path"/>
</javac>
</target>
<target name="runUnitTests" depends="compile">
<junit printsummary="yes" haltonfailure="no">
<jvmarg value="-Dfile.encoding=UTF-8"/>
<classpath refid="unit.test.path"/>
<formatter type="plain"/>
<batchtest fork="yes" todir="${buildtest.dir}">
<fileset dir="${test.dir}">
<include name="**/TestsVorgabe.java"/>
<exclude name="**/AllTests.class"/>
<exclude name="**/*$*.class"/>
</fileset>
</batchtest>
</junit>
</target>
我已经尝试了很多方法来包含 .jars 和很多编译测试的方法,但似乎没有任何效果所以我最终得到了这个(也不起作用)。
您使用 javac 将您的源代码编译到 ${build.dir}
但您没有将其添加到 junit 任务的类路径中,这是 documentation:
<classpath>
<pathelement location="${build.tests}"/>
<pathelement path="${java.class.path}"/>
</classpath>
或检查this example(在示例中:${web.classes.dir}
)。
尝试将 build.dir 添加到 junit 任务类路径,希望对您有所帮助!