Ant没有使用Junit Target获取Junit文件

时间:2013-07-25 11:03:51

标签: ant junit

我正在使用junit ant目标来运行junits。当我单独运行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

但是类在classpath中。请帮我调试一下。

我的构建文件是,

<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>

1 个答案:

答案 0 :(得分:0)

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