5

私のアプリでRESTサービスコールを作成するためにアンドロイドスプリングRestTemplateを使用しています。私は、RESTサービスコールを模擬したアンドロイド計測テストを追加しました。アンドロイドスタジオから実行している間 すべての私のテストは、罰金を実行しているが、場合build.gradleAndroidTestコマンドラインから実行中に失敗しました:app:connectedDebugAndroidTest

androidTestCompile("org.springframework:spring-test:3.2.8.RELEASE") 

./gradlew clean :app:connectedDebugAndroidTest 

を使用して、端末からの春のテスト依存関係を実行中のテストは、春モッククラスのロードに失敗しましたandroidTestCompileではなくcompileに変更され、アンドロイドテストは端末からうまく動作しています。 私は私の生産APKのこの依存関係を望んでいないので、感謝します。

このログテストに

08-05 00:04:12.585 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.asm.commons.JSRInlinerAdapter 08-05 00:04:12.587 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.asm.commons.TryCatchBlockSorter 08-05 00:04:12.593 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.cglib.transform.AbstractProcessTask 08-05 00:04:12.593 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.cglib.transform.AbstractTransformTask 08-05 00:04:12.603 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.core.convert.support.ConvertingPropertyEditorAdapter 08-05 00:04:12.610 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.core.io.ResourceEditor 08-05 00:04:12.611 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.core.io.support.ResourceArrayPropertyEditor 08-05 00:04:12.617 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.http.MockHttpInputMessage 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.http.MockHttpOutputMessage 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.http.client.MockClientHttpRequest 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.http.client.MockClientHttpResponse 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.jndi.ExpectedLookupTemplate 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.jndi.SimpleNamingContext 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.jndi.SimpleNamingContextBuilder 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.DelegatingServletInputStream 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.DelegatingServletOutputStream 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockBodyContent 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockExpressionEvaluator 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockFilterChain 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockFilterConfig 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockHttpServletRequest 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockHttpServletResponse 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockHttpSession 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockJspWriter 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockMultipartFile 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockMultipartHttpServletRequest 08-05 00:04:12.622 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockPageContext 08-05 00:04:12.622 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockRequestDispatcher 08-05 00:04:12.623 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockServletConfig 08-05 00:04:12.623 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.MockServletContext 08-05 00:04:12.628 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.PassThroughFilterChain 08-05 00:04:12.628 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.portlet.MockActionRequest 08-05 00:04:12.629 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.portlet.MockActionResponse 08-05 00:04:12.629 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.portlet.MockBaseURL 08-05 00:04:12.629 22274-22302/com.libin.androiduitesting E/TestLoader: Could not find class: org.springframework.mock.web.portlet.MockCacheControl 08-05 00:04:12.630 22274-22302/com.libin.androiduitesting E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner Process: com.libin.androiduitesting, PID: 22274 java.lang.NoClassDefFoundError: org.springframework.mock.web.portlet.MockClientDataRequest at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:324) at android.support.test.internal.runner.TestLoader.doLoadClass(TestLoader.java:92) at android.support.test.internal.runner.TestLoader.loadIfTest(TestLoader.java:113) at android.support.test.internal.runner.TestRequestBuilder.loadClassesFromClassPath(TestRequestBuilder.java:801) at android.support.test.internal.runner.TestRequestBuilder.build(TestRequestBuilder.java:747) at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:354) at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:260) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1879)

+0

'testCompile'についてはどうですか? –

+0

は 'androidTestCompile'を' testCompile'に変更して@ cricket_007と言いました。それは働いていますか? – piotrek1543

+0

いいえ、どうしますか?testCompileに追加された依存関係は単体テストにのみ含まれています。私はandroidTestを実行しています。 androidTest – Libin

答えて

1

を起動しているときに、テストのためにneccesaryあるモッククラスが欠けているように思えます。スプリングテストjarをダウンロードし、すべてのmockingクラスが内部にあるかどうかを確認してください。たとえば、パッケージorg.springframework.mock.web.portletからクラスorg.springframework.mock.web.portlet.MockClientDataRequestをエクスポートする必要があります。

this issueのように、模擬クラスの依存関係が失われた不幸なjarビルドを使用することができます。

また、春のフレームワークを更新することもできます。最新のものはすでに4.3.2です。

+0

いいえ私はクラスを逃していません。実行を開始するときに、モジュール全体のテストを実行しながら、モジュールが削除されていることを確認します。個々のクラスまたはパッケージに対してテストが実行されている場合はすべて問題ありません – Libin

関連する問題