I have the following tasks in ant:
<target name="init-junit" depends="init">
<mkdir dir="${junit.reports.individual}" />
<property name="running-junit" value="true" />
</target>
<target name="run-tests" depends="init-junit, compile">
<junit>
<classpath refid="classpath" />
<formatter type="xml" />
<batchtest todir="${junit.reports.individual}">
<fileset dir="${dir.build}" includes="**/*Test*" />
</batchtest>
</junit>
</target>
<target name="compile-reports" depends="run-tests">
<junitreport todir="${junit.reports}" tofile="junit-report.xml">
<fileset dir="${junit.reports.individual}" />
<report format="frames" todir="${junit.reports}/html" />
</junitreport>
</target>
with ${dir.build}
being the directory with all my .class
files. The jUnit tests work when I run them in eclipse, but fail when I run them through ant (either run through eclipse or terminal); they each throw the following exception:
org.fscit.{name of class} java.lang.ClassNotFoundException: org.fscit.{name of class} at java.lang.ClassLoader.loadClass开发者_如何学Python(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247)
I have junit-4.8.2.jar
in my lib
folder, which is in the classpath with the id, classpath
, and I have build.xml on my project root directory, with its basedir
property set to .
. Can anyone help me?
You need to have the destination directory of your classes in the classpath. You should have ${dir.build}
in your classpath element.
<path id="classpath">
<pathelement location="${dir.build}"/>
Use pathelement task
<pathelement location="${dir.build}" />
instead of fileset task
<fileset dir="${dir.build}" />
It works for me (ant version is 1.7.1)
精彩评论