当尝试使用以下build.xml中的runtestsreport任务从ANT运行我的JUnit测试时,我遇到了java.lang.NoClassDefFoundError问题;我知道其他任务可以正常工作,问题在于测试的实际运行。
我已经尝试了很多调整基于问题张贴在这里,但我不能解决它;我真正需要的是一个可以搭档的开发人员,但他们都回家了。
有人能帮忙吗?
build.xml文件
<property name="build" location="C:<path on my machine>workspaceESSbuild"/>
<property name="testsbuild" location="C:<path on my machine>workspaceESSbuildesstestapptests"/>
<property name="frameworkbuild" location="C:<path on my machine>workspaceESSbuildesstestappframework"/>
<property name="rawtestreports" location="C:<path on my machine>workspaceESSreportsraw"/>
<property name="htmltestreports" location="C:<path on my machine>workspaceESSreportshtml"/>
<property name="reports" location="C:<path on my machine>workspaceESSreports"/>
<property name="src" location="C:<path on my machine>workspaceESSsrc"/>
<property name="testsrc" location="C:<path on my machine>workspaceESSsrcesstestapptests"/>
<property name="seleniumtools" location="C:<path on my machine>workspaceESStoolsjunit-4.8.2"/>
<property name="junittools" location="C:<path on my machine>workspaceESStoolsselenium-2.0rc2"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${rawtestreports}"/>
<mkdir dir="${htmltestreports}"/>
</target>
<path id="tools.classpath">
<fileset dir="${seleniumtools}" includes="**/*.jar"/>
<fileset dir="${junittools}" includes="**/*.jar"/>
</path>
<target name="compile" depends="init" description="compile the source" >
<javac srcdir="${src}" destdir="${build}" classpathref="tools.classpath" includeantruntime="false"/>
</target>
<target name="frameworkjar" depends="compile">
<jar destfile="${frameworkbuild}/jar/framework.jar" basedir="${frameworkbuild}" />
</target>
<target name="testsjar" depends="compile">
<jar destfile="${testsbuild}/jar/tests.jar" basedir="${testsbuild}" />
</target>
<path id="test.classpath">
<fileset dir="${seleniumtools}" includes="**/*.jar"/>
<fileset dir="${junittools}" includes="**/*.jar"/>
<fileset dir="${testsbuild}/jar" includes="**/*.jar"/>
<fileset dir="${frameworkbuild}/jar" includes="**/*.jar"/>
</path>
<target name="runtests" depends="compile, frameworkjar, testsjar" description="runs the tests" >
<junit printsummary="yes" haltonfailure="no" showoutput="yes" fork="no">
<classpath refid="test.classpath" />
<batchtest fork="yes" todir="${rawtestreports}">
<formatter type="xml"/>
<fileset dir="${testsrc}">
<include name="**/*.java"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="runtestsreport" depends="runtests">
<junitreport todir="${reports}">
<fileset dir="${rawtestreports}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${htmltestreports}" />
</junitreport>
</target>
<target name="clean" description="Clean up">
<delete dir="${build}"/>
<delete dir="${reports}"/>
</target>
我得到这个错误(每个测试类都有这种类型的错误)
Credentials (wrong name: esstestapp/tests/Credentials)
java.lang.NoClassDefFoundError: Credentials (wrong name: esstestapp/tests/Credentials)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)...
我已经在-verbose模式下运行了ant来检查类路径,但我看不到问题(即使我知道它就在我面前)
[junit] Implicitly adding C:Program Filesapache-ant-1.8.2libant-launcher
.jar;C:Program Filesapache-ant-1.8.2libant.jar;C:Program Filesapache-ant-1
.8.2libant-junit.jar;C:Program Filesapache-ant-1.8.2libant-junit4.jar to C
LASSPATH
[junit] Executing 'C:Program FilesJavajdk1.6.0_25jrebinjava.exe' with
arguments:
[junit] '-classpath'
[junit] Executing 'C:Program FilesJavajdk1.6.0_25jrebinjava.exe' with
arguments:
[junit] '-classpath'
[junit] 'C:<path on my machine>workspaceESStoolsjunit-4.8.2junit.jar;C:User
swaltersjworkspaceESStoolsjunit-4.8.2junitsrc.jar;C:<path on my machine>worksp
aceESStoolsselenium-2.0rc2apache-mime4j-0.6.jar;C:<path on my machine>workspace
ESStoolsselenium-2.0rc2bsh-1.3.0.jar;C:<path on my machine>workspaceESStoolsse
lenium-2.0rc2cglib-nodep-2.1_3.jar;C:<path on my machine>workspaceESStoolsseleni
um-2.0rc2commons-codec-1.4.jar;C:<path on my machine>workspaceESStoolsselenium-2
.0rc2commons-collections-3.2.1.jar;C:<path on my machine>workspaceESStoolsseleni
um-2.0rc2commons-io-2.0.1.jar;C:<path on my machine>workspaceESStoolsselenium-2.
0rc2commons-lang-2.4.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2
commons-logging-1.1.1.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2
cssparser-0.9.5.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2guava-
r09.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2hamcrest-all-1.1.j
ar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2htmlunit-2.8.jar;C:Use
rswaltersjworkspaceESStoolsselenium-2.0rc2htmlunit-core-js-2.8.jar;C:User
swaltersjworkspaceESStoolsselenium-2.0rc2httpclient-4.0.2.jar;C:Userswal
tersjworkspaceESStoolsselenium-2.0rc2httpcore-4.0.1.jar;C:<path on my machine>w
orkspaceESStoolsselenium-2.0rc2httpmime-4.0.1.jar;C:<path on my machine>workspac
eESStoolsselenium-2.0rc2jcommander-1.13.jar;C:<path on my machine>workspaceESS
toolsselenium-2.0rc2jna.jar;C:<path on my machine>workspaceESStoolsselenium-2.0
rc2json-20080701.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2juni
t-dep-4.8.1.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2nekohtml-1
.9.14.jar;C:<path on my machine>workspaceESStoolsselenium-2.0rc2sac-1.3.jar;C:U
serswaltersjworkspaceESStoolsselenium-2.0rc2selenium-java-2.0rc2-srcs.jar;
C:<path on my machine>workspaceESStoolsselenium-2.0rc2selenium-java-2.0rc2.jar;C
:<path on my machine>workspaceESStoolsselenium-2.0rc2serializer-2.7.1.jar;C:Use
rswaltersjworkspaceESStoolsselenium-2.0rc2testng-6.0.1-nobsh-noguice.jar;C
:<path on my machine>workspaceESStoolsselenium-2.0rc2xalan-2.7.1.jar;C:Userswa
ltersjworkspaceESStoolsselenium-2.0rc2xercesImpl-2.9.1.jar;C:Userswalters
jworkspaceESStoolsselenium-2.0rc2xml-apis-1.3.04.jar;C:<path on my machine>work
spaceESSbuildesstestapptestsjartests.jar;C:<path on my machine>workspaceESSb
uildesstestappframeworkjarframework.jar;C:<path on my machine>workspaceESS;C:P
rogram FilesJavajre6libextQTJava.zip;C:Program Filesapache-ant-1.8.2lib
ant-launcher.jar;C:Program Filesapache-ant-1.8.2libant.jar;C:Program Files
apache-ant-1.8.2libant-junit.jar;C:Program Filesapache-ant-1.8.2libant-jun
it4.jar'
任何能帮助我运行测试的人都将非常感激。
感谢詹姆斯我观察到如果我编辑测试。然后我看到的错误切换到ClassNotFound,这是有意义的,因为它没有引用包含类的.jar文件。
<fileset dir="${testsbuild}/jar" includes="**/*.jar"/>
<fileset dir="${frameworkbuild}/jar" includes="**/*.jar"/>
在测试中出现上述2行。classpath是高兴地发现他们,但错误的名称,这是错误,我不知道如何修复。
由以下jar命令引起的问题:
<jar destfile="${testsbuild}/jar/tests.jar" basedir="${testsbuild}" />
testsbuild属性应该设置为
<property name="testsbuild" location="C:<path on my machine>workspaceESSbuild"/>
文件Credentials.class被编译为类esstestapp.tests.Credentials。它需要在类路径中找到,如文件:
esstestapp/测试/Credentials.class