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
Java Junit给出错误_Java_Ant_Junit - Fatal编程技术网

Java Junit给出错误

Java Junit给出错误,java,ant,junit,Java,Ant,Junit,我可以让我的junit类从eclipse开始工作。但是它对蚂蚁不起作用。我收到了这个错误消息 空测试:导致错误 com.fourhome.commons.Test_设备类型 java.lang.ClassNotFoundException:com.fourhome.commons.Test\u设备类型 我的ant类路径中有junit-3.8.2.jar。还有com.fourhome.commons <property name="tests" value="${basedir}/tests

我可以让我的junit类从eclipse开始工作。但是它对蚂蚁不起作用。我收到了这个错误消息

空测试:导致错误 com.fourhome.commons.Test_设备类型 java.lang.ClassNotFoundException:com.fourhome.commons.Test\u设备类型

我的ant类路径中有junit-3.8.2.jar。还有com.fourhome.commons

<property name="tests" value="${basedir}/tests/" />

<path id="test.classpath">

  <pathelement location="${classesdir}" />
  <pathelement location="${builddir}" />
  <pathelement location="${basedir}\tests\junit-3.8.2.jar" />        

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

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

<target name="test">
  <junit fork="yes" haltonfailure="no">
    <batchtest fork="yes"  todir="${builddir}">
        <fileset dir="${tests}">              
           <include name="**/Test*.java" />             
        </fileset>
    </batchtest>
    <classpath refid="test.classpath" />
    <formatter type="brief" usefile="false" />
  </junit>
</target>

解释在您的错误消息中。您选择的是类名,但不是.class文件。显然,您必须编译JUnit测试和生产类,并将它们放在类路径上。Eclipse会自动执行此操作,但您必须在Ant中明确执行此操作。

您认为com.fourhome.commons.Test\u设备类型在哪里?如果它在类路径上,我会感到惊讶。在哪里定义${builddir}属性,它设置为什么?
package com.fourhome.commons;

import junit.framework.TestCase;
import junit.*;

public class Test_DeviceTypes extends TestCase {

public void testIsTypeValid() { 
    assertEquals(DeviceTypes.isTypeValid(DeviceTypes.TYPE_BINARY_SENSOR), true);        
}   
}