以下是build.gradle
文件中的配置:
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
androidTestCompile 'com.android.support:support-annotations:24.2.1'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.6.3'
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.4.1'
androidTestCompile 'com.google.truth:truth:0.30'
androidTestCompile 'com.github.ignaciotcrespo:frutilla:0.7.1'
androidTestCompile 'org.mockito:mockito-core:2.2.9'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.squareup.okhttp3:okhttp-testing-support:3.4.1'
开始all my tests,或只是one of them,例如:
@Test
public void test_Parse_JSONRepo_ParsesRepoDTO() throws IOException {
ObjectMapper loJSONMapper = new ObjectMapper();
String lsRepoData = mLocalifyClient.localify().loadRawFile(R.raw.repo_octocat);
DTORepo loRepoDTO = loJSONMapper.readValue(lsRepoData, DTORepo.class);
assertThat(loRepoDTO).isNotNull();
assertThat(loRepoDTO.name).isEqualTo("git-consortium");
}
我在Android Studio中收到以下消息:
Started running tests
Test running failed: Instrumentation run failed due to 'java.lang.AbstractMethodError'
Empty test suite.
答案 0 :(得分:2)
测试套件输出总是非常简洁。在这种情况下,最好检查“Android Monitor”logcaat输出是什么。
答案就在那里:
java.lang.AbstractMethodError: abstract method "org.mockito.plugins.MockMaker$TypeMockability org.mockito.plugins.MockMaker.isTypeMockable(java.lang.Class)"
at org.mockito.internal.util.MockUtil.typeMockabilityOf(MockUtil.java:29)
at org.mockito.internal.util.MockCreationValidator.validateType(MockCreationValidator.java:22)
at org.mockito.internal.creation.MockSettingsImpl.validatedSettings(MockSettingsImpl.java:168)
at org.mockito.internal.creation.MockSettingsImpl.confirm(MockSettingsImpl.java:162)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
at org.mockito.Mockito.mock(Mockito.java:1632)
at org.mockito.Mockito.mock(Mockito.java:1545)
at fr.guddy.androidstarter.tests.mock.MockModuleRest.<init>(MockModuleRest.java:24)
at fr.guddy.androidstarter.tests.mock.MockApplication.buildComponent(MockApplication.java:41)
at fr.guddy.androidstarter.ApplicationAndroidStarter.onCreate(ApplicationAndroidStarter.java:70)
at fr.guddy.androidstarter.tests.mock.MockApplication.onCreate(MockApplication.java:31)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1024)
at android.support.test.runner.MonitoringInstrumentation.callApplicationOnCreate(MonitoringInstrumentation.java:323)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5403)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1545)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
这是Mockito版本高于2.0.17-beta
而不与dexmaker-mockito
合作的已知错误。关于它的更多信息here。
解决方案只是使用不同版本的Mockito
:
androidTestCompile 'org.mockito:mockito-core:2.0.17-beta'