3

我正在使用来自 Jake Wharton 的 Double Espresso,它有助于在 Android Studio 和 Gradle 中集成 Google Espresso。问题在于兼容性库(support-v4),哪些类在测试版本中不可用:

java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests.testSuiteConstructionFailed(TestSuiteBuilder.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onStart(GoogleInstrumentationTestRunner.java:167)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1840)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.test.suitebuilder.TestMethod.instantiateTest(TestMethod.java:87)
at android.test.suitebuilder.TestMethod.createTest(TestMethod.java:73)
at android.test.suitebuilder.TestSuiteBuilder.addTest(TestSuiteBuilder.java:262)
at android.test.suitebuilder.TestSuiteBuilder.build(TestSuiteBuilder.java:184)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:379)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(GoogleInstrumentationTestRunner.java:114)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5142)
at android.app.ActivityThread.access$1500(ActivityThread.java:156)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: net.skoumal.project.activity.MainActivity
at net.skoumal.project.test.MainActivityTest.<init>(MainActivityTest.java:30)
... 19 more
4

1 回答 1

2

解决方案非常简单,只需在 gradle.build 中更改此行:

androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3')

通过为兼容性库添加排除:

androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3'
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') {
    exclude group: 'com.android.support'
}
于 2014-06-04T10:30:07.470 回答