[英]jUnit tests work in Eclipse, but fail when I run them through ant
I have the following tasks in ant:我在 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. ${dir.build}
是我所有.class
文件的目录。 The jUnit tests work when I run them in eclipse, but fail when I run them through ant (either run through eclipse or terminal); 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(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 .
我的
lib
文件夹中有junit-4.8.2.jar
,该文件夹位于 id 为classpath
的类路径中,并且我的项目根目录中有 build.xml ,其basedir
属性设置为.
. . 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.您的类路径元素中应该有
${dir.build}
。
<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)它对我有用(蚂蚁版本是 1.7.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.