8

私が取り組んでいるAndroidテストプロジェクトでセットアップされた次のテストケースの例を持っています。

package com.whatever.test;

import static org.junit.Assert.fail;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.xtremelabs.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class SomeClassTest {

  @Test
  public void testFromJson() {
    fail("Not yet implemented");
  }

}

私はjunit実行構成をセットアップしました.junit4で実行され、Java 6(mac os xデフォルト)とoracleのjdk 7の両方で試しました.

どのように試しても、常に次のエラーが発生します

    java.lang.TypeNotPresentException: Type com.xtremelabs.robolectric.RobolectricTestRunner not present
at sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:28)
at sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:57)
at $Proxy4.value(Unknown Source)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Caused by: java.lang.ClassNotFoundException: com.xtremelabs.robolectric.RobolectricTestRunner
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:95)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:107)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.annotation.AnnotationParser.parseSig(AnnotationParser.java:370)
at sun.reflect.annotation.AnnotationParser.parseClassValue(AnnotationParser.java:351)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:280)
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:222)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3070)
at java.lang.Class.getAnnotation(Class.java:3029)
at org.junit.internal.builders.IgnoredBuilder.runnerForClass(IgnoredBuilder.java:13)
... 12 more

adt パッケージにバンドルされている最新の Android SDK (API レベル 17) を使用しており、robolectric 1.1 を外部 JAR として使用しています。

そのようにEclipseでテストを実行することが最善ではない場合、私は代替案を受け入れます。

編集: Robolectric がクラスパスで Android の前に表示されることを確認するように提案されました。そして、問題は解決しません。

編集2 :コメントの提案に従いましたが、どれも機能していないようで、エラーが続きます。

4

1 に答える 1

1

次の 2 つのディスカッションを見たことがありますか。

Maven Surefire プラグインを使用して Robolectric テストを実行すると ClassNotFoundException が発生する

https://groups.google.com/forum/?fromgroups=#!topic/robolectric/6c8WmE-qjlk

于 2013-01-24T17:28:26.260 に答える