gpt4 book ai didi

带有 Dagger 的 Android Espresso

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:08:17 25 4
gpt4 key购买 nike

我正在尝试使用 Espresso 尤其是 Double-Espresso 库运行 android 仪器测试。

我知道 Espresso 已经依赖于 dagger 1.2.1,我的应用也使用相同的 dagger 版本。所以我这样声明依赖。

// 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)));
}

}

但是测试失败并且日志显示找不到 dagger 的方法之一。

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。

替换这个:

// 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'

关于带有 Dagger 的 Android Espresso,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25528916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com