当抛出:Zip​​Exception运行JUnit测试 [英] ZipException when running junit tests

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

问题描述

我一直妄图让蚂蚁执行用的JUnit一些测试。任何意见将是多少AP preciated。我是pretty新双方蚂蚁和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.

作为一个快速的总结,我在做什么是试图让蚂蚁执行一个非常简单的测试,类路径看起来不错考虑从蚂蚁-debug输出。我得到一个空的测试误差测试谁的类文件在classpath中明确提到。此外,我得到一个抛出:Zip​​Exception,我不知道那是什么的。

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);
    }   
}

有一个包中的一些测试,这一次只是看到为什么一切都失败了。它失败抛出:Zip​​Exception。

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>

蚂蚁编译一切正常,并期待把一切都在正确的地方。但它似乎无法找到我的测试...这里有一个小片是什么蚂蚁吐出来时,我与-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.

它看起来很像测试用例在类路径中,所以我不知道发生了什么......也许这件事情做的抛出:Zip​​Exception但我不知道...

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文件到classpath中。这是行不通的。类文件不是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.

这篇关于当抛出:Zip​​Exception运行JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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