我正在使用Android Spring RestTemplate
来调用我的应用程序上的REST服务。 我添加了包括模拟REST服务调用的Android Instrumentation测试。当从Android Studio运行时,所有测试都正常运行,但是当使用终端运行时,测试无法加载Spring模拟类。
./gradlew clean :app:connectedDebugAndroidTest
build.gradle 中的 Spring 测试依赖
androidTestCompile("org.springframework:spring-test:3.2.8.RELEASE")
如果我改为使用
compile
而不是androidTestCompile
,Android测试会在终端上正常运行。由于我不想让这个依赖出现在我的生产APK中,所以需要帮助,谢谢。以下是启动测试时的日志记录。
08-05 00:04:12.585 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.asm.commons.JSRInlinerAdapter. 08-05 00:04:12.587 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.asm.commons.TryCatchBlockSorter. 08-05 00:04:12.593 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.cglib.transform.AbstractProcessTask. 08-05 00:04:12.593 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.cglib.transform.AbstractTransformTask. 08-05 00:04:12.603 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.core.convert.support.ConvertingPropertyEditorAdapter. 08-05 00:04:12.610 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.core.io.ResourceEditor. 08-05 00:04:12.611 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.core.io.support.ResourceArrayPropertyEditor. 08-05 00:04:12.617 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.http.MockHttpInputMessage. 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.http.MockHttpOutputMessage. 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.http.client.MockClientHttpRequest. 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.http.client.MockClientHttpResponse. 08-05 00:04:12.618 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.jndi.ExpectedLookupTemplate. 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.jndi.SimpleNamingContext. 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.jndi.SimpleNamingContextBuilder. 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.DelegatingServletInputStream. 08-05 00:04:12.619 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.DelegatingServletOutputStream. 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockBodyContent. 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockExpressionEvaluator. 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockFilterChain. 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockFilterConfig. 08-05 00:04:12.620 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockHttpServletRequest. 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockHttpServletResponse. 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockHttpSession. 08-05 00:04:12.621 22274-22302/com.libin.androiduitesting E/TestLoader:找不到类:org.springframework.mock.web.MockJspWriter. 08-05 00:04:12.621 22274
testCompile
怎么办? - OneCricketeerandroidTestCompile
更改为testCompile
,正如@cricket_007所说。它是否有效? - piotrek1543