Ant和JUnit:测试未执行

时间:2014-05-08 08:31:42

标签: java ant junit

使用Ant,您需要运行JUnit-test。要使用此代码:

<target name="tempTest">
        <mkdir dir="<folder in which to create the class-file>" />
        <javac destdir="<folder in which to create the class-file>"
               srcdir="<folder in which the java-file with junit-test>"
               debug="on"
               memorymaximumsize="128m"
               fork="true"
               encoding="utf-8">
            <classpath>
                <fileset dir="<folder, which is located in junit.jar>" includes="junit.jar"/>
            </classpath>
        </javac>
        <junit printsummary="on" haltonfailure="no">
            <classpath>
                <fileset dir="<folder, which is located in junit.jar>" includes="junit.jar"/>
                <pathelement location="<folder in which to create the class-file (in this step, class-file has been created in this folder)>"/>
            </classpath>
            <formatter type="plain"/>
            <batchtest todir="<folder in which the file will be created for output to a test error>">
                <fileset dir="<folder in which the java-file with junit-test>"/>
            </batchtest>
        </junit>
</target>


代码类参加测试:

package ForTests;

import org.junit.Test;

public class TempTest {

    @Test
    public void testTemp() {

        System.err.print("ERROR FOR TESTS");

    }

}


但是,运行ant-script文件时会显示错误:

Testsuite: TempTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

    Caused an ERROR
TempTest
java.lang.ClassNotFoundException: TempTest
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:30)


请告诉我,如何解决问题?


UPD:

问题已经解决。

为了运行junit-test line必须

<batchtest todir="<folder in which the file will be created for output to a test error>">
    <fileset dir="<folder in which the java-file with junit-test>"/>
</batchtest>

替换

<batchtest todir="<folder in which the file will be created for output to a test error>">
    <fileset dir="<folder in which to create the class-file (in this step, class-file has been created in this folder)>"/>
</batchtest>

0 个答案:

没有答案