浓缩咖啡意图。 NoSuchMethodError UsageTracker

时间:2017-10-22 12:08:32

标签: java android testing gradle android-espresso

剧透警报:我对浓咖啡很新。我正在编写一个测试,其中一个意图启动并获得以下内容:

      java.lang.NoSuchMethodError: No interface methodtrackUsage(Ljava/lang/String;)V in class Landroid/support/test/internal/runner/tracker/UsageTracker; or its super classes (declaration of 'android.support.test.internal.runner.tracker.UsageTracker' appears in /data/app/com.app.test-2/base.apk:classes3.dex)
at android.support.test.espresso.intent.Intents.<clinit>(Intents.java:93)
at com.app.features.main.MainActivityTest.when_logout_button_is_clicked_then_view_is_not_visible(MainActivityTest.java:70)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at android.support.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at android.support.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1970)

这是相关的gradle代码:

ext {
    support_lib_version = '25.3.1'
    play_services_lib_version = "11.0.4"
    okhttp_version = '3.4.1'
}

configurations.all {
resolutionStrategy {
    force "com.android.support:support-annotations:$support_lib_version"
    force "com.android.support:support-v4:$support_lib_version"
    force "com.android.support:design:$support_lib_version"
    force "com.android.support:appcompat-v7:$support_lib_version"
    force "com.squareup.okhttp3:okhttp:$okhttp_version"
}


//Testing
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.2.0'
androidTestCompile 'com.github.andrzejchm.RESTMock:android:0.2.2'
androidTestCompile 'com.android.support.test:runner:1.0.1'
androidTestCompile 'com.android.support.test:rules:1.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'

测试代码(不应该相关,但仍然......)

@RunWith(AndroidJUnit4.class)
public class MainActivityTest {

@Rule
public ActivityTestRule<MainActivity> activityTestRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void when_logout_button_is_clicked_then_view_is_not_visible() {
    Intents.init();
    openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
    onView(withText("Logout")).perform(click());
    intended(hasComponent(LoginSignUpActivity.class.getName()));
    Intents.release();
}

我没有使用proguard。 Aaany关于如何解决这个问题的想法? Defo看起来像依赖性问题......

1 个答案:

答案 0 :(得分:1)

解决方案,以防万一对任何人都有帮助:

androidTestCompile ('com.android.support.test.espresso:espresso-intents:3.0.1'

而不是

androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2'

不敢相信我没想到这个......