Java Junit给出错误
我可以让我的junit类从eclipse开始工作。但是它对蚂蚁不起作用。我收到了这个错误消息 空测试:导致错误 com.fourhome.commons.Test_设备类型 java.lang.ClassNotFoundException:com.fourhome.commons.Test\u设备类型 我的ant类路径中有junit-3.8.2.jar。还有com.fourhome.commonsJava 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
<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);
}
}