Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidTest Failed while running from command line :app:connectedDebugAndroidTest

I'm using android spring RestTemplate for making REST service calls on my app. I added android Instrumentation test which includes mocking the REST service calls. All my test are running fine while running from android studio, but the test failed to load spring mock class while running from terminal using

   ./gradlew clean :app:connectedDebugAndroidTest

The spring test dependency on build.gradle

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

If i change to compile instead of androidTestCompile , the android test are running fine from terminal . Since i don't want this dependency on my production APK any help , appreciated.

This the log while starting the test

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)

like image 290
Libin Avatar asked Nov 08 '22 11:11

Libin


1 Answers

Seems like you are missing mocking classes which are neccesary for testing. Try dowloading spring-test jar and check if all mocking classes are inside - for example, it should export class org.springframework.mock.web.portlet.MockClientDataRequest from package org.springframework.mock.web.portlet.

You can be using some unfortunate jar build where dependiencies for mocking classes were lost like in this issue.

Also you can try updating spring framework, the latest is already 4.3.2.

like image 196
Jehy Avatar answered Nov 15 '22 04:11

Jehy