dimanche 22 octobre 2017

Espresso intents. NoSuchMethodError UsageTracker

Spoiler alert: I'm quite new to espresso. I'm writing a test where an intent is launched and getting the following:

      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)

This is the relevant gradle code:

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'

The test code (shouldn't be relevant but still...)

@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();
}

I don't use proguard. Aaany idea on how to fix this? Defo looks like a dependencies problem...

Aucun commentaire:

Enregistrer un commentaire