0

我正在使用 junit ant 目标来运行 junit。当我单独运行 Junit 文件时,junit 运行正常。当我尝试使用 ant 脚本时,junit 测试用例没有被执行。它向我显示了错误,

Running x.SimpleTest
    [junit] Testsuite: x.SimpleTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit]     Caused an ERROR
    [junit] x.SimpleTest
    [junit] java.lang.ClassNotFoundException: x.SimpleTest
    [junit]     at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    [junit]     at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    [junit]     at java.lang.Class.forName0(Native Method)
    [junit]     at java.lang.Class.forName(Class.java:247)
    [junit]     at org.eclipse.ant.internal.launching.remote.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
    [junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.run(InternalAntRunner.java:424)
    [junit]     at org.eclipse.ant.internal.launching.remote.InternalAntRunner.main(InternalAntRunner.java:138)
    [junit] Test x.SimpleTest FAILED

但是该类位于类路径中。请帮助我进行调试。

我的构建文件是,

<property file="build.properties" />

<path id="libirary">

    <fileset dir="${lib}">
        <include name="**.*jar" />
    </fileset>

</path>

<path id="applicationClassPath">
    <path id="classpath1" refid="libirary" />
    <pathelement id="classpath2" location="${build.classes.dir}" />
</path>


<path id="application.classpath">
    <pathelement path="${java.class.path}" />

</path>

<path id="class.path">
    <fileset dir="${build.classes.dir}" />
</path>






<property name="classPath" refid="applicationClassPath" />

<target name="clean">
    <delete dir="${build.classes.dir}" />
    <delete dir="${build.dir}" />
    <delete dir="${dist.dir}" />
</target>

<target name="init" depends="clean">
    <mkdir dir="${build.classes.dir}" />
    <mkdir dir="${dist.dir}" />
</target>


<target name="compile" depends="init">
    <javac encoding="ISO-8859-1" destdir="${build.classes.dir}" srcdir="${src.dir}" debug="true" verbose="false">
        <classpath>
            <path refid="libirary" />
        </classpath>
    </javac>
</target>

<target name="jar" depends="compile">

    <jar destfile="${dist.dir}/${jar.filename}.jar">

        <fileset dir="${build.classes.dir}" />
        <zipfileset dir="${lib}" includes="**/*.jar" />

        <manifest>
            <attribute name="Main-Class" value="${main.file.name}" />
        </manifest>

    </jar>

</target>


<target name="junit" depends="compile">


    <echo message="classpath= ${classPath}" />
    <junit printsummary="yes" description="true" filtertrace="yes" showoutput="yes">
        <formatter type="plain" usefile="false" />



        <classpath>
            <path refid="applicationClassPath" />


        </classpath>


        <test name="x.SimpleTest" filtertrace="true">
        </test>
    </junit>
</target>

4

1 回答 1

0

现在已经解决了。这是由于类路径错误。谢谢大家的回复。

于 2013-07-25T12:21:11.823 回答