簡體   English   中英

Android Espresso with Dagger

[英]Android Espresso with Dagger

我正在嘗試使用Espresso特別是Double-Espresso庫運行android儀器測試。

我知道Espresso已經依賴於dagger 1.2.1而我的應用也使用相同的匕首版本。 所以我聲明了這樣的依賴。

// dagger-compiler already includes dagger.
compile 'com.squareup.dagger:dagger-compiler:1.2.1'

androidTestCompile 'com.google.guava:guava:16.0'
androidTestCompile 'javax.annotation:javax.annotation-api:1.2'
androidTestCompile 'com.google.code.findbugs:jsr305:1.3.9'
androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') {
    exclude group: 'com.android.support', module: 'support-v4'
    exclude group: 'com.google.guava', module: 'guava'
    exclude group: 'com.squareup.dagger'
    //exclude group: 'javax.annotation', module: 'javax.annotation-api'
}

我的測試看起來像這樣。

@LargeTest
public class IntegrationTest extends ActivityInstrumentationTestCase2<LoginSelectMethodActivity> {

    public IntegrationTest() {
    // This constructor was deprecated - but we want to support lower API levels.
        super("com.google.android.apps.common.testing.ui.testapp", LoginSelectMethodActivity.class);
    }
    @Override
    public void setUp() throws Exception {
        super.setUp();
        getActivity();
    }

    @LargeTest
    public void test_actionButtonEnableWhenInputsAreValid() {
        Espresso.onView(ViewMatchers.withId(R.id.signin_email))
                .perform(ViewActions.click());

        Espresso.onView(ViewMatchers.withText(R.id.et_email))
                .perform(ViewActions.typeText("valid@email.com"), ViewActions.pressKey(KeyEvent.KEYCODE_ENTER),
                        ViewActions.typeText("aGoodP455w0rd"), ViewActions.pressKey(KeyEvent.KEYCODE_ENTER));

        Espresso.onView(ViewMatchers.withId(R.id.b_signin))
                .check(matches(withText(R.string.sign_in)));
    }

}

然而,測試失敗,日志說它找不到匕首的方法之一。

08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug W/dalvikvm﹕ VFY: unable to resolve virtual method 15010: Ldagger/ObjectGraph;.get (Ljava/lang/Class;)Ljava/lang/Object;
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0015
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug I/dalvikvm﹕ Could not find method dagger.ObjectGraph.get, referenced from method com.google.android.apps.common.testing.ui.espresso.Espresso.registerIdlingResources
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug W/dalvikvm﹕ VFY: unable to resolve virtual method 15010: Ldagger/ObjectGraph;.get (Ljava/lang/Class;)Ljava/lang/Object;
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0009
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug I/dalvikvm﹕ Could not find method dagger.ObjectGraph.get, referenced from method com.google.android.apps.common.testing.ui.espresso.Espresso.registerLooperAsIdlingResource
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug W/dalvikvm﹕ VFY: unable to resolve virtual method 15010: Ldagger/ObjectGraph;.get (Ljava/lang/Class;)Ljava/lang/Object;
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug I/dalvikvm﹕ Could not find method dagger.ObjectGraph.get, referenced from method com.google.android.apps.common.testing.ui.espresso.Espresso.setFailureHandler
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug W/dalvikvm﹕ VFY: unable to resolve virtual method 15010: Ldagger/ObjectGraph;.get (Ljava/lang/Class;)Ljava/lang/Object;
08-27 22:24:13.979    4074-4087/com.trumpia.android.loyaltea.debug D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
...
08-27 22:24:14.031    4074-4087/com.trumpia.android.loyaltea.debug I/TestRunner﹕ ----- begin exception -----
08-27 22:24:14.031    4074-4087/com.trumpia.android.loyaltea.debug I/TestRunner﹕ java.lang.NoSuchMethodError: dagger.ObjectGraph.get
            at com.google.android.apps.common.testing.ui.espresso.Espresso.onView(Espresso.java:51)

我在Android Studio中使用GoogleInstrumentationTestRunner運行測試。 希望任何人都可以為此給我一些啟示。

你需要依靠匕首。

替換這個:

// dagger-compiler already includes dagger.
compile 'com.squareup.dagger:dagger-compiler:1.2.1'

有了這個:

compile 'com.squareup.dagger:dagger:1.2.1'
provided 'com.squareup.dagger:dagger-compiler:1.2.1'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM