【问题标题】:Android Espresso intending not working on android version > 5Android Espresso 打算在 android 版本 > 5 上不工作
【发布时间】:2017-05-04 06:15:13
【问题描述】:

我有一个 Espresso UI 测试,它使用 intending 在单击按钮时存根启动新活动。 以下代码在 Android 5.1 及更低版本的设备上运行良好,但在任何 Android 版本高于intending 的设备上似乎无法按照文档中的说明工作。

@Test
public void UnitIshTest() throws Exception {
    Instrumentation.ActivityResult result =
            new Instrumentation.ActivityResult(Activity.RESULT_OK, new Intent());

    intending(hasComponent(TestingController.class.getName())).respondWith(result);
    onView(withId(R.id.layout_with_button)).perform(click());
}

基本上,我想检查单击特定按钮时是否触发了意图。但我实际上并不想要启动新 Activity 的意图。

我尝试将意图行替换为:intending(isInternal()).respondWith(result); 以捕捉任何可能的意图,但也没有成功。

知道如何在 Android 6 和 7 设备上使用相同的功能吗?

【问题讨论】:

  • 为什么投反对票?

标签: java android android-espresso android-testing ui-testing


【解决方案1】:

尝试在您的 gradle 文件中进行这些更改

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2') {

  exclude group: 'com.android.support', module: 'support-annotations'
 }
androidTestCompile('com.android.support.test:runner:0.3') {

  exclude group: 'com.android.support', module: 'support-annotations'
 }

【讨论】:

  • 感谢您的回复。我的 build.gradle 文件中已经有了这些。
【解决方案2】:

我在issue tracker 上创建了一个错误票证,因为意图似乎不像文档中描述的那样工作,并且目标活动实际上是在具有较新版本的 android 的设备上启动的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 2015-10-10
    • 1970-01-01
    相关资源
    最近更新 更多