junit的ant目标

我有Suite.java文件:

public class EshopServiceTestSuite extends TestSuite { public static Test suite() { TestSuite suite = new TestSuite(); suite.addTestSuite(ImpactActionTypeTest.class); suite.addTestSuite(ProductServiceTest.class); return suite; } public static void main(String[] args) { TestRunner.run(EshopServiceTestSuite .class); } } 

ImpactActionTypeTest.java文件扩展了TestCase它工作正常。 但是ProductServiceTest.java

扩展ESWTestCase,实习生扩展TestCase,这会导致junit atrget失败。

 java.lang.reflect.InvocationTargetException Caused by: java.lang.ExceptionInInitializerError at org.apache.log4j.Logger.getLogger(Logger.java:94) at com.bgc.ecm.core.test.ElNinoAbstractTestCase.<clinit>(ElNinoAbstractTestCase.java:62) at java.lang.reflect.Constructor.newInstance(Constructor.java:494) at com.bgc.EshopServiceTestSuite.suite(EshopServiceTestSuite.java:41) Caused by: sun.misc.InvalidJarIndexException: Invalid index at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:769) .....   <![CDATA[log4j:WARN Caught Exception while in Loader.getResource. This may be innocuous. sun.misc.InvalidJarIndexException: Invalid index 

EshopServiceTestSuite.java:41有代码suite.addTestSuite(ProductServiceTest.class); Log4j被称为:

 - C:\build_libs\ESW\junit-3.8.1.jar - C:\build_libs\ESW\log4j-1.2.15.jar - C:\build_libs\ESW\log4j-1.2.8.jar - C:\build_libs\ESW\mailapi.jar 

为什么发生这种exception?

看起来类加载器正在某个jar中查找类文件而无法找到它。

正如你所说的.java文件 – 仔细检查所有文件是否已编译并添加到jar文件中。

刚刚看到log4j中发生exception – 在执行测试时仔细检查log4j.jar是否在类路径上。

检查您的jar /其中一个jar子是否包含索引文件( META_INF/INDEX.LIST )。 如果是,请查看它,它可能包含无效的索引条目。

这是一篇关于你的exception的文章: 为什么会发生InvalidJarIndexException?