I can get my junit class to work from eclipse. But it does’nt work on ant. I get this error message.
Null Test: Caused an ERROR
com.fourhome.commons.Test_DeviceTypes
java.lang.ClassNotFoundException: com.fourhome.commons.Test_DeviceTypes
I have junit-3.8.2.jar in my ant classpath. Also have 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>
junit code
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);
}
}
The explanation is in your error message. You’re picking up the class name but not the .class files. You have to compile your JUnit tests (and your production classes, obviously) and put them on the classpath. Eclipse does this automatically, but you have to explicitly do so in Ant.