【问题标题】:InstrumentationTestCase is deprecate in api24api 24 中不推荐使用 Instrumentation 测试用例
【发布时间】:2017-11-17 12:31:49
【问题描述】:

在 api24 中不推荐使用 InstrumentationTestCase

我可以用什么来代替保持相同的功能?

例如:

// Start the MainActivity as the first activity...
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setClassName(instrumentation.getTargetContext(), MainActivity.class.getName());
    instrumentation.startActivitySync(intent);

我看过一些关于InstrumentationRegistry的东西,但功能却大不相同。

【问题讨论】:

    标签: android testing instrumentation testcase


    【解决方案1】:

    使用类IntstrumentRegistry 并从其方法中

    getInstrumentation() 返回当前运行的检测。

    您可以使用任何方法,例如:

    startActivitySync(Intent 意图) 开始一个新的活动并等待它开始运行,然后再返回。

    编辑:这是仪器参考链接:https://developer.android.com/reference/android/app/Instrumentation.html

    【讨论】:

    • 谢谢 Sara,但我如何检查是否有正确的活动更改,我目前使用的是:currentActivity = getInstrumentation().waitForMonitorWithTimeout(monitor, TIME_OUT);assertThat(currentActivity, is(notNullValue()));
    • 对不起,我没明白你的意思?您是说在使用 InstrumentationRegistry 及以上方法getInstrumentation().waitForMonitorWithTimeout(monitor, TIME_OUT); 后您无法实现目标?
    • 我可以实现,但是使用InstrumentationTestCase,我想知道对于InstrumentationRegistry,我该如何做这个逻辑,因为方法不同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多