2

私はこれに完全に混乱し、慌てています。私の理解では、それは機能するはずですが、理由はわかりません。

Eclipseワークベンチでいくつかのテストを実行するだけのtychoビルドがあります。ただし、私のテストはすべて、この種の例外で失敗します。

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リポジトリはここにあります:https ://github.com/grails/grails-sts-tests

いくつかのテストを実行するだけのシンプルな単一のプラグインであることがわかります。テストスイートは、依存関係として指定されている他のリポジトリのプラグインからのテストで構成されています。他のリポジトリにあるテストプラグインは別のCIサーバーで実行され、NoClassDefFoundErrorの問題は発生しないことに注意してください。他のCIサーバーを調べましたが、何も違いはありません(残念ながら、このCIサーバーは公開されていないため、リンクを共有できません)。

問題を示すハドソンビルドジョブはここにあります:http://hudson.grails.org/job/grails-sts-tests-2.0.x/17/console

4

4 に答える 4

2

非常によく似た問題がありました。原因は、junit フレームワークがカスタム クラスローダーを作成して使用しようとすることであり、これは Eclipse プラグイン クラスローダーとうまく連携しません。Tycho で単体テストを実行するためのガイドラインがいくつかあります。

  1. 単体テストはプラグイン フラグメントにあります。単体テスト フラグメントは、JUnit に依存しています。
  2. pom は、単体テストでのシステム クラス ローダーの使用をオフにする必要があります。これが、junit テスト クラスが失われる原因です。
  3. 次に、標準プラグイン (正確には eclipse-plugin) と同じパッケージを使用します。

したがって、単純な POM (私たちにとって) は次のようになります。

<?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>

これにより、単体テスト フレームワークが Eclipse プラグイン クラスローダーを使用し、すべてのクラスが検出されるようになります。

于 2012-07-10T20:25:36.983 に答える
1

まだ誰も質問に答えることができませんが、直接役に立たなかったとしても情報をありがとう.

私はいくつかの進歩を遂げました。現在、60回のテストのうち45回に合格しています。tycho-surefire-pluign 構成エリアに、次のような追加の依存関係を追加しただけです。

                <dependencies>
                    <dependency>
                        <type>p2-installable-unit</type>
                        <artifactId>org.junit</artifactId>
                        <version>0.0.0</version>
                    </dependency>
                    ...
                </dependencies>

残念ながら、残りのテストはまだ同じで失敗していNoClassDefFoundErrorます。依存関係をさらに追加する必要があり、すべてが機能する可能性があります。

于 2012-07-17T05:48:59.937 に答える
0

いくつかのサードパーティのjarに依存するAndroidプロジェクトでjunitテストを実行する場合にも同様の問題が発生しました。問題は、依存するjarの1つがjdk v1.5でビルドされ、それ以外はすべて1.6であるということでした。1つのライブラリを1.6でビルドされた新しいバージョンに更新したところ、エラーはなくなりました。

同じ問題なのか、tychoを設定したり更新したりできるのかはわかりませんが、一見の価値があるかもしれません。

于 2012-07-10T16:15:44.763 に答える
0

私がチェックすること:

  1. NoClassDefFoundErrorの原因を確認してください。UnSupportedClassVersionErrorやExceptionINinitializationErrorが最も一般的であるなど、さまざまな理由があります。
  2. JVMオプション-verbose:classを使用して、クラスローディングログを取得し、必要なクラスの予想されるアーティファクトからクラスがロードされていることを確認します。
于 2012-07-09T15:33:13.803 に答える