Eclipse Tycho测试因java.lang.NoClassDefFoundError而失败:junit/framework/AssertionFailedError
我被这件事弄得不知所措,目瞪口呆。在我的理解中,它应该起作用,但我不知道为什么 我有一个tycho构建,它只是在eclipse工作台上运行一些测试。但是,我所有的测试都失败了,出现了这样的异常:Eclipse Tycho测试因java.lang.NoClassDefFoundError而失败:junit/framework/AssertionFailedError,eclipse,maven,junit,junit4,tycho,Eclipse,Maven,Junit,Junit4,Tycho,我被这件事弄得不知所措,目瞪口呆。在我的理解中,它应该起作用,但我不知道为什么 我有一个tycho构建,它只是在eclipse工作台上运行一些测试。但是,我所有的测试都失败了,出现了这样的异常: java.lang.NoClassDefFoundError: junit/framework/AssertionFailedError at org.grails.ide.eclipse.commands.test.AbstractCommandTest.tearDown(AbstractComman
java.lang.NoClassDefFoundError: junit/framework/AssertionFailedError
at org.grails.ide.eclipse.commands.test.AbstractCommandTest.tearDown(AbstractCommandTest.java:112)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at junit.framework.TestSuite.runTest(TestSuite.java:243)
at junit.framework.TestSuite.run(TestSuite.java:238)
at org.springsource.ide.eclipse.commons.tests.util.ManagedTestSuite.run(ManagedTestSuite.java:231)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:123)
at org.eclipse.tycho.surefire.osgibooter.OsgiSurefireBooter.run(OsgiSurefireBooter.java:84)
at org.eclipse.tycho.surefire.osgibooter.AbstractUITestApplication$1.run(AbstractUITestApplication.java:35)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3529)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3182)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1022)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:916)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:585)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:540)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
at org.eclipse.tycho.surefire.osgibooter.UITestApplication.runApplication(UITestApplication.java:31)
at org.eclipse.tycho.surefire.osgibooter.AbstractUITestApplication.run(AbstractUITestApplication.java:114)
at org.eclipse.tycho.surefire.osgibooter.UITestApplication.start(UITestApplication.java:37)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ClassNotFoundException: junit.framework.AssertionFailedError
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:501)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:421)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:412)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 54 more
这对我来说毫无意义org.junit
和org.junit4
是运行测试的包以及包含AbstractCommandTest
的包的依赖项。这些测试在我的工作区内运行时通过,那么为什么maven/tycho不能加载junit类呢
如果有帮助的话,我很乐意提供更多信息,比如github回购协议的链接
编辑:提供更多详细信息 github回购协议如下: 您可以看到它是一个简单的插件,只运行一些测试。测试套件由来自其他存储库中指定为依赖项的插件的测试组成。请注意,位于其他存储库中的测试插件在另一台CI服务器上运行,并且没有NoClassDefFoundError问题。我查看了另一台CI服务器,没有发现任何不同之处(不幸的是,此CI服务器不可公开访问,因此我无法共享指向它的链接)
显示问题的hudson build作业如下:我要检查的事项:
-verbose:class
获取类加载日志,并检查是否从所需类的预期工件中加载了类我会做些什么来检查:
-verbose:class
获取类加载日志,并检查是否从所需类的预期工件中加载了类我在一个Android项目上运行junit测试时遇到了一个类似的问题,该项目依赖于一些第三方JAR,问题是其中一个依赖的JAR是用jdk v1.5构建的,其他所有东西都是1.6。我将one库更新为使用1.6构建的更新版本,然后错误消失了
不知道这是否是同一个问题,或者你是否可以配置tycho或更新它,但这可能值得一看….我在一个依赖于一些第三方JAR的Android项目上运行junit测试时遇到了类似的问题,最终的问题是,其中一个依赖JAR是用JDKv1.5构建的,其他所有内容都是1.6。我将one库更新为使用1.6构建的更新版本,然后错误消失了
不知道是否存在相同的问题,或者您是否可以配置tycho或更新它,但可能值得一看……我们也遇到了类似的问题。原因是junit框架试图创建和使用自定义类加载器,而这在eclipse插件类加载器中不起作用。我们现在遵循一些关于使用Tycho运行单元测试的指导原则
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>master</artifactId>
<groupId>mgws</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../mgws/build-environment/pom.xml</relativePath>
</parent>
<groupId>mgws</groupId>
<artifactId>mgws.spectral.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>JUnitTest</id>
<goals>
<goal>test</goal>
</goals>
<phase>install</phase>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
主人
mgws
0.0.1-快照
../../mgws/build-environment/pom.xml
mgws
光谱测试
1.0.0-SNAPSHOT
eclipse插件
org.apache.maven.plugins
maven surefire插件
2.12
朱尼特
测试
安装
假的
这使得单元测试框架使用eclipse插件类加载器,现在它可以找到所有的类。我们遇到了非常类似的问题。原因是junit框架试图创建和使用自定义类加载器,而这在eclipse插件类加载器中不起作用。我们现在遵循一些关于使用Tycho运行单元测试的指导原则
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>master</artifactId>
<groupId>mgws</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../mgws/build-environment/pom.xml</relativePath>
</parent>
<groupId>mgws</groupId>
<artifactId>mgws.spectral.test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<executions>
<execution>
<id>JUnitTest</id>
<goals>
<goal>test</goal>
</goals>
<phase>install</phase>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4.0.0
主人
mgws
0.0.1-快照
../../mgws/build-environment/pom.xml
mgws
光谱测试
1.0.0-SNAPSHOT
eclipse插件
org.apache.maven.plugins
maven surefire插件
2.12
朱尼特
测试
安装
假的
这使得单元测试框架使用eclipse插件类加载器,现在它可以找到所有的类。仍然没有人能够回答这个问题,但是感谢您提供的信息,即使它没有直接的用处 我取得了一些进展。我60次考试中有45次通过了。我只是在tycho surefire pluign配置区域添加了一些额外的依赖项,如下所示:
<dependencies>
<dependency>
<type>p2-installable-unit</type>
<artifactId>org.junit</artifactId>
<version>0.0.0</version>
</dependency>
...
</dependencies>
p2可安装单元
org.junit
0.0.0
...