繁体   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