ZipException when running junit tests

I tried in vain to get ant to run some tests written in junit. Any advice would be much appreciated. I am new to both ant and Java, so please be patient.

As a brief summary of what I'm doing, you are trying to get ant to run a very simple test, the classpath looks fine, given the output from ant -debug. I get an error with an error for a test for which the cool file is explicitly specified in the classpath. Also, I get a ZipException, I don't know what that means.

Here is the test test 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); } } 

There are several tests in the package, it was just to understand why everything failed. It does not work with ZipException.

and here is a little 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 compiles everything in order and hopes to put everything in the right places. but he cannot find my tests ... here is a small part 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 for the ugly conclusion there, everything I have to work with now.

it is very similar to the test windows in the classpath, so I don’t know what is happening ... Maybe this has something to do with ZipException, but I don’t know ...

+8
java classpath exception junit ant
source share
2 answers

You added EasyTest.class as a JAR file to the classpath. This does not work. Class files are not JAR archives, so the class loader throws an error when trying to load classes from it.

+7
source share

I assume you are running jUnit 3. You might want to create a TestCase class that is not an abstract class. In addition, you have a default constructor, otherwise jUnit will not know how to create a test class.

In your case, it should be:

 package testmanagment; import junit.framework.*; public class EasyTest extends TestCase { public EasyTest() { super("Easy Test"); } public void setUp() { } public void testSeeMee() throws Exception { assertTrue(true); } public void testSeeMeetoo() throws Exception { assertTrue(true); } } 
+1
source share

All Articles