使用Junit Java的Ant classNotFound异常

时间:2015-03-23 23:32:23

标签: java xml junit ant classnotfoundexception

我尝试运行单元测试时遇到ClassNotFound异常。 以下是运行测试的.xml脚本。

<?xml version="1.0"?>
<project name="Embedded CST316 Project Test Build" default="targets" basedir=".">

    <!-- set global properties for this build -->
    <property name="src" location="airAutomation/src" />
    <!-- <property name="test" location="airAutomation/test" /> -->
    <property name="test" location="airAutomation/testAirUI/airUI/pkg" />
    <property name="build" location="airAutomation/classes" />
    <property name="test.dir" location="airAutomation/classes/tests" />
    <property name="test.report.dir" location="airAutomation/testreport" />

    <path id="junit.class.path">
        <pathelement location="${build}" />
        <pathelement location="airAutomation/lib/xbjlib-1.0.1.jar" />
        <pathelement location="airAutomation/lib/junit-4.12.jar" />
        <pathelement location="airAutomation/lib/hamcrest-core-1.3.jar" />
    </path>

    <target name="targets">
        <!-- Display available targets -->
        <echo message="targets are clean, prepare, compile, junit"/>
    </target>

    <target name="clean">
        <!-- Delete the ${build} directory tree -->
        <delete dir="${build}" />
        <delete dir="${test.report.dir}" />
        <!-- <delete dir="${test}" /> --> 
    </target>

    <target name="prepare">
        <!-- Create the time stamp -->
        <tstamp/>
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}" />
        <!-- <mkdir dir="${test}" /> -->
        <mkdir dir="${test.dir}" />
        <mkdir dir="${test.report.dir}" />
    </target>

    <target name="compile" depends="clean, prepare"
        description="Compile Unit Tests">
        <!-- Compile all classes -->
        <javac srcdir="${src}"
            includeantruntime="false"
            destdir="${build}" >
            <classpath refid="junit.class.path" />
        </javac>
        <javac srcdir="${test}"
            includeantruntime="false"
            destdir="${test.dir}" >
            <classpath refid="junit.class.path" />
        </javac>
    </target>

    <target name="junit" depends="compile"
        description="Execute Unit Tests">
        <!-- Run Junit tests -->
        <junit printsummary="yes" fork="true" haltonfailure="yes">
            <classpath refid="junit.class.path" />
            <classpath>
                <pathelement location="${test.dir}" />
             </classpath>
            <formatter type="xml" />
            <batchtest todir="${test.report.dir}">
                <fileset dir="airAutomation/testAirUI/airUI/pkg/">
                    <include name="**Test*.java" />
                </fileset>
            </batchtest>
        </junit>
    </target>

</project>

这是xml末尾的输出。

<error message="roomTest" type="java.lang.ClassNotFoundException">
java.lang.ClassNotFoundException: roomTest
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:171)
</error>

测试位于文件夹&#34; airAutomation / testAirUI / airUI / pkg /&#34;

我是否需要在其他地方指定此文件夹(我创建了一些文件夹来保存测试的输出)?

0 个答案:

没有答案