アンドロイド計測ツールでMockitoフレームワークを使用しようとしていますが、正しく初期化できません。 org.mockito.internal.creationでjava.lang.ExceptionInInitializerError MockitoによるAndroid計測テスト
:
class MainKontorTest extends ActivityInstrumentationTestCase2<MainActivity> { @Mock Dependency bar; @Override public void setUp() { super.setUp(); MockitoAnnotations.initMocks(this); } public void testSomething() { Foo foo = new Foo(bar); } }
私はこのテストを実行しようとすると、私は次のエラーとスタックトレースを取得する:私は、次のテストクラスを持っています.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:95) at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57) at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise (ClassImposterizer.java:49) at org.mockito.internal.creation.cglib.Cgl (MockitoCore.java:59) at ibMockMaker.createMock (MockAnnotationProcessor.java:33) at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.process)。 Javaの:16) org.mockito.internal.configuration.DefaultAnnotationEngine.processでorg.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(DefaultAnnotationEngine.java:43) (DefaultAnnotationEngine.java:66) でorg.mockitoで。内部構成。注入内部統制のエンジニア。プロセスの依存関係の通知(注入AnnotationEngine.java:71)org.arkadiy.moduledelegationsampleでorg.mockito.MockitoAnnotations.initMocksでorg.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:55) で(MockitoAnnotations.java:108) 。 uu.main.MainKontorTest.setUp(MainKontorTest.java:20) at junit.framework.TestCase.runBare(TestCase.java:132) at junit.framework.TestResult $ 1.protect(TestResult.java:115) at android .support.test.internal.runner.junit3.AndroidTestResult.runProtected(AndroidTestResult.java:77) at junit.framework.TestResult.run(TestResult.java:118) android.support.test.internal.runner.junit3 .AndroidTestResult.run(AndroidTestResult.java:55) at junit.framework.TestCase.run(TestCase.ja VA:junit.framework.TestSuite.runTestでandroid.support.test.internal.runner.junit3.NonLeakyTestSuite $ NonLeakyTest.run(NonLeakyTestSuite.java:63) (TestSuite.java:243)のJUnitで で124) 。フレームワーク.TestSuite.run(TestSuite.java:238) android.support.test.internal.runner.junit3.DelegatingTestSuite.run(DelegatingTestSuite.java:103) android.support.test.internal.runner.junit3。 AndroidTestSuite.run(AndroidTestSuite.java:69) (android.support.test.internal.runner.junit3.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90) at org.junit.runners.Suite.runChild(Suite.java: 128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access $ 000 ParentRunner.java:58) at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner (JUnitCore.java:115) android.support.test.internal.runner.TestExecutor.execute(TestExecutor。java:54) android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:240) android.app.Instrumentation $ InstrumentationThread.run(Instrumentation.java:1869) 原因:org.mockito。 cglib.core.CodeGenerationException:java.lang.reflect.InvocationTargetException - > null at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238) at org.mockito.cglib.core.KeyFactory $ジェネレータ.create(KeyFactory.java:145) at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117) at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109) (エンハンサー.java:70) ... 40 more 原因:java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(ネイティブメソッド) at java.lang.reflect.Method.invoke(Method.java:372) org.mockito.cglib.core.AbstractClassGenerator.createでorg.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385) (AbstractClassGenerator.java:220)によって引き起こさ ... 45もっと で : java.lang.UnsupportedOperationExceptionが:もっと ... 49どのように
(ClassLoader.java:300)java.lang.ClassLoader.defineClassでクラスファイル のこのタイプをロードすることはできませんインストルメンテーションテストでMockitoを使用できますか?私はより新しいRule apiとMockitoを使ってみましたが、エラーは同じでした。
gradleを使用してAPKを作成していない場合は、http://stackoverflow.com/questions/29290795/attempt-to-mockito-mock-any-class-generates-exceptionininitializererror/41350001#41350001詳細情報 –