配置蚂蚁运行单元测试。图书馆应放在何处?应该如何类路径进行配置?避免抛出:Zip​​Exception [英] Configuring ant to run unit tests. Where should libraries be? How should classpath be configured? avoiding ZipException

查看:183
本文介绍了配置蚂蚁运行单元测试。图书馆应放在何处?应该如何类路径进行配置?避免抛出:Zip​​Exception的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行使用蚂蚁我的JUnit测试。测试使用的是JUnit 4测试套件拉开序幕。如果我从Eclipse运行这个直接完成测试,没有错误。但是,如果我从运行蚂蚁那么多的测试失败,此错误重复一遍又一遍,直到junit任务崩溃。

I'm trying to run my junit tests using ant. The tests are kicked off using a JUnit 4 test suite. If I run this direct from Eclipse the tests complete without error. However if I run it from ant then many of the tests fail with this error repeated over and over until the junit task crashes.


    [junit] java.util.zip.ZipException: error in opening zip file
    [junit]     at java.util.zip.ZipFile.open(Native Method)
    [junit]     at java.util.zip.ZipFile.(ZipFile.java:114)
    [junit]     at java.util.zip.ZipFile.(ZipFile.java:131)
    [junit]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028)
    [junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147)
    [junit]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.nextElement(AntClassLoader.java:130)
    [junit]     at org.apache.tools.ant.util.CollectionUtils$CompoundEnumeration.nextElement(CollectionUtils.java:198)
    [junit]     at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:43)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.checkForkedPath(JUnitTask.java:1128)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeAsForked(JUnitTask.java:1013)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:834)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue(JUnitTask.java:1785)
    [junit]     at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:785)
    [junit]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
    [junit]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    [junit]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    [junit]     at java.lang.reflect.Method.invoke(Method.java:597)
    [junit]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    [junit]     at org.apache.tools.ant.Task.perform(Task.java:348)
    [junit]     at org.apache.tools.ant.Target.execute(Target.java:357)
    [junit]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
    [junit]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    [junit]     at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
    [junit]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    [junit]     at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
    [junit]     at org.apache.tools.ant.Main.runBuild(Main.java:758)
    [junit]     at org.apache.tools.ant.Main.startAnt(Main.java:217)
    [junit]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
    [junit]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

我的测试运行的任务如下:

my test running task is as follows:


    <target name="run-junit-tests" depends="compile-tests,clean-results">
    	<mkdir dir="${test.results.dir}"/>
    	<junit failureproperty="tests.failed" fork="true" showoutput="yes" includeantruntime="false">
    		<classpath refid="test.run.path" />
    		<formatter type="xml" />
    		<test name="project.AllTests" todir="${basedir}/test-results" />
    	</junit>
    	<fail if="tests.failed" message="Unit tests failed"/>
    </target>

我已经验证了classpath中包含以下以及所有程序code和库:

I've verified that the classpath contains the following as well as all of the program code and libraries:


ant-junit.jar
ant-launcher.jar
ant.jar
easymock.jar
easymockclassextension.jar
junit-4.4.jar

我试着调试找出哪些压缩文件,它试图用没有运气开,我尝试切换 includeantruntime 和我试过运行蚂蚁与蚂蚁-lib测试/库,其中测试/库包含了Ant和JUnit库。

I've tried debugging to find out which ZipFile it is trying to open with no luck, I've tried toggling includeantruntime and fork and i've tried running ant with ant -lib test/libs where test/libs contains the ant and junit libraries.

是什么原因导致这种异常,或你如何配置蚂蚁成功运行单元测试是感激地收到任何信息。

Any info about what causes this exception or how you've configured ant to successfully run unit tests is gratefully received.

蚂蚁1.7.1(Ubuntu的),JAVA 1.6.0_10,JUnit 4.4的

ant 1.7.1 (ubuntu), java 1.6.0_10, junit 4.4

感谢。

更新 - 修正
发现了我的问题。我已经使用包括相对于一个pathelement这个文件集在我的道路我classes目录是导致.class文件被打开作为ZipFiles这当然引发了异常。

Update - Fixed Found my problem. I had included my classes directory in my path using a fileset as opposed to a pathelement this was causing .class files to be opened as ZipFiles which of course threw an exception.

推荐答案

找到了我的问题。我一直在使用包括我classes目录在我的路径中的文件集,而不是一个 pathelement 这是造成.class文件被打开作为ZipFiles这当然引发了异常。

Found my problem. I had included my classes directory in my path using a fileset as opposed to a pathelement this was causing .class files to be opened as ZipFiles which of course threw an exception.

这篇关于配置蚂蚁运行单元测试。图书馆应放在何处?应该如何类路径进行配置?避免抛出:Zip​​Exception的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆