运行 junit 测试时出现 ZipException [英] ZipException when running junit tests

查看:33
本文介绍了运行 junit 测试时出现 ZipException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图让 ant 执行一些用 junit 编写的测试,但徒劳无功.任何建议将不胜感激.我对 ant 和 Java 都很陌生,所以请耐心等待.

I've been trying in vain to get ant to execute some tests written in junit. Any advice would be much appreciated. I'm pretty new to both ant and Java so please be patient.

作为一个快速总结,我正在做的是尝试让 ant 执行一个非常简单的测试,考虑到 ant -debug 的输出,类路径看起来没问题.对于在类路径中明确提到的类文件的测试,我收到空测试错误.另外,我收到了一个 ZipException,我不知道这是怎么回事.

As a quick summary, what i'm doing is trying to get ant to execute a very simple test, the classpath looks ok considering the output from ant -debug. I'm getting a null test error for a test who's class file is explicitly mentioned in the classpath. Also, i'm getting a ZipException, i dont know what that's about.

这是我正在尝试运行的测试用例:

Here's a testcase i'm trying to run:

package testmanagment;
import junit.framework.*;

public abstract class EasyTest extends TestCase
{

    public EasyTest(String name)
    {
        super(name);
    }

    protected void setUp()
    {}

    protected void testSeeMee() throws Exception
    {
        assertTrue(true);
    }

    protected void testSeeMeetoo() throws Exception
    {
        assertTrue(true);
    }   
}

包中有一些测试,这个只是为了看看为什么一切都失败了.它因 ZipException 而失败.

There are a few tests in the package, this one was just to see why everything was failing. it fails with ZipException.

这是我的make文件的一点点:

and here's a little bit of my make file:

  <property name="src" value="src/"/> 
     <property name="build" value="build/"/>  
     <property name="test" value="${build}test/"/>
     <property name="testreportsdir" value="${test}reports/"/>
     <property name="classdir" value="${build}classes/"/>
     <property name="lib" value="lib/"/> 

    <path id="files-classpath">  
        <fileset dir="lib/" >  
            <include name="*.jar"/>  
        </fileset>  
    </path> 

    <path id="tests-classpath">
        <path refid="files-classpath"/>
        <pathelement location="${classdir}/"/>
    </path>

    <path id="tests-runpath">
        <path refid="tests-classpath"/>
        <fileset dir="${test}/">
            <include name="*.class"/>
            <include name="**/*.class"/>
            <include name="testmanagment/*.class"/>
            <include name="*.*"/>
            <include name="**/*.*"/>
            <include name="testmanagment/*.*"/>
        </fileset>
        </path>

blah blah blah

    <target name="test" depends="compile_tests">
        <junit haltonfailure="true"  printsummary="false">
            <classpath refid="tests-runpath"/>
            <formatter type="brief" usefile="false"/>
            <test name="testmanagment.EasyTest"/>
            <test name="testmanagment.TestUser"/>
            <test name="testmanagment.TestTest"/>
                </junit>
    </target>

ant 编译一切正常,并希望将所有内容放在正确的位置.但它似乎无法找到我的测试......这是当我使用 -debug 选项运行它时蚂蚁吐出的一小部分.

ant compiles everything fine, and looks to put everything in the right places. but it cant seem to find my tests... here's a little piece of what ant spat out when i ran it with the -debug option.

 [junit] Using CLASSPATH /host/Users/Sheena/Desktop/School/Software dev/lab_project/lib/junit-4.8.1.jar:/host/Users/Sheena/Desktop/School/Software dev/lab_project/lib/sqlitejdbc-v056.jar:/host/Users/Sheena/Desktop/School/Software dev/lab_project/build/classes:/host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/EasyTest.class:/host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/TestTest.class:/host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/TestUser.class:/usr/share/ant/lib/junit.jar:/usr/share/java/ant-launcher-1.7.1.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-junit.jar
Class org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter loaded from parent loader (parentFirst)
Finding class testmanagment.EasyTest
Ignoring Exception java.util.zip.ZipException: error in opening zip file reading resource testmanagment/EasyTest.class from /host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/EasyTest.class
Ignoring Exception java.util.zip.ZipException: error in opening zip file reading resource testmanagment/EasyTest.class from /host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/TestTest.class
Ignoring Exception java.util.zip.ZipException: error in opening zip file reading resource testmanagment/EasyTest.class from /host/Users/Sheena/Desktop/School/Software dev/lab_project/build/test/testmanagment/TestUser.class
    [junit] Testsuite: testmanagment.EasyTest
    [junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
    [junit] 
    [junit] Null Test:  Caused an ERROR

对不起,那里的输出很丑,我现在只需要处理这些.

sorry about the ugly output there, it's all i have to work with for now.

它看起来很像测试用例在类路径中,所以我不知道发生了什么......也许这与 ZipException 有关,但我不知道......

it looks very much like the testcases are in the classpath, so i dont know what's happening... Maybe it's something to do with the ZipException but i dont know...

推荐答案

您将 EasyTest.class 作为 JAR 文件添加到类路径中.这不起作用.类文件不是 JAR 档案,因此类加载器在尝试从中加载类时会抛出错误.

You added EasyTest.class as a JAR file to the classpath. This doesn't work. Class files aren't JAR archives, so the classloader throws an error when it tries to load classes from it.

这篇关于运行 junit 测试时出现 ZipException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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