Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ant中执行Junit测试-noclassdeffounderror错误名称_Junit_Ant_Javac_Build.xml - Fatal编程技术网

在ant中执行Junit测试-noclassdeffounderror错误名称

在ant中执行Junit测试-noclassdeffounderror错误名称,junit,ant,javac,build.xml,Junit,Ant,Javac,Build.xml,我正在尝试使用ant执行一些junit测试套件 这是我的文件夹结构 垃圾箱 解放党 src 试验 build.xml 首先,我编译源位置中的所有文件,然后编译测试文件夹中的java文件 测试文件夹(编译的.class文件)的整个结构保存在bin文件夹中,该文件夹内部如下所示 bin测试所有测试 | -套房-SetupSuite.class -星际级 allTests文件夹中的测试是在suites文件夹中的suites中使用的测试 我正在尝试启动这些套件,但经常出现错误: ant junit

我正在尝试使用ant执行一些junit测试套件

这是我的文件夹结构

  • 垃圾箱
  • 解放党
  • src
  • 试验
  • build.xml
首先,我编译源位置中的所有文件,然后编译测试文件夹中的java文件

测试文件夹(编译的.class文件)的整个结构保存在bin文件夹中,该文件夹内部如下所示

bin测试所有测试 | -套房-SetupSuite.class -星际级

allTests文件夹中的测试是在suites文件夹中的suites中使用的测试

我正在尝试启动这些套件,但经常出现错误:

ant junit java.lang.noclassdeffounderror错误名称

我很确定类路径有问题,但我不知道是什么。我试着改变


还有一个错误:

java.lang.ClassNotFoundException:SetupSuite.class

这是我的build.xml文件

<project name="MyTest" basedir=".">

    <!--Common properties -->
    <property name="src.dirname" value="src" />
    <property name="test.dirname" value="test" />
    <property name="lib.dirname" value="lib" />
    <property name="bin.dirname" value="bin" />
    <property name="src.encoding" value="utf8" />
    <property name="src.version" value="1.7" />
    <property environment="env" />

    <!-- Paths for MyTest -->
    <property name="MyTest.dir" value="${basedir}" />
    <property name="MyTest.src.dir" value="${MyTest.dir}\${src.dirname}" />
    <property name="MyTest.test.dir" value="${MyTest.dir}\${test.dirname}" />
    <property name="MyTest.dest.dir" value="${MyTest.dir}\${bin.dirname}" />
    <property name="MyTest.lib.dir" value="${MyTest.dir}\${lib.dirname}" />

    <path id="classpath">
        <pathelement location="${MyTest.lib.dir}\junit.jar" />
        <pathelement location="${MyTest.test.dir}\test\suites\" />
    </path>

    <target name="compile-MyTest-src" >
        <myjavac srcdir="${MyTest.src.dir}" destdir="${MyTest.dest.dir}" classpath="{MyTest.lib.dir}\junit.jar"/>
    </target>

    <target name="compile-MyTest-test" depends="compile-MyTest-src">
        <path id='libs'>
            <fileset dir= "${MyTest.lib.dir}\" includes="**/*.jar"/>
        </path>
    <myjavac srcdir="${MyTest.test.dir}\" destdir="${MyTest.dest.dir}" classpathref = 'libs'/>
    </target>

    <target name="execute-tests" depends="compile-MyTest-src,compile-MyTest-test">
        <junit printsummary="yes" haltonfailure="no" showoutput="yes">
        <formatter type = "brief" usefile = "false" />
        <classpath refid="classpath" />
            <test name="SetupSuite"/>
        </junit>
    </target>   

   <!-- General compiler settings -->
    <presetdef name="myjavac">
        <javac classpathref="classpath" debug="on" includeantruntime="false" encoding="${src.encoding}" source="${src.version}" target="${src.version}" />
    </presetdef>

</project>

您需要将测试名称设置为SetupSuite的名称:

<test name="alltests.suites.SetupSuite"/>


已解决。我不得不将hamcrest-core-1.3.jar文件添加到类路径中

请向我们展示有问题的测试套件;我尝试了,得到了java.lang.ClassNotFoundException:SetupSuite.class
<test name="alltests.suites.SetupSuite"/>