gpt4 book ai didi

android - registerIdlingResources 弃用替换不起作用

转载 作者:行者123 更新时间:2023-12-03 07:29:47 24 4
gpt4 key购买 nike

我正在尝试更换我的 Espresso registerIdlingResourcesunregisterIdlingResources不推荐使用 IdlingRegistry 的方法根据android文档的方法。

我的一些测试在更新之前有效,现在不再有效......这些测试可以单独工作,但不能一起工作。

我注意到与旧版本(Espresso 类)有一点不同,这条线在 IdlingRegistry 中不存在类(class) :

baseRegistry.sync(IdlingRegistry.getInstance().getResources(), IdlingRegistry.getInstance().getLoopers());

我认为这是 sync方法对我的自定义 IdlingResource 非常重要...

如果没有这条线,我如何同步我的 Looper?

谢谢你的帮助。

编辑:我使用 EspressoCore 3.0.1 和 runner/rules 1.0.1

Edit2:已指定弃用的文档链接: HereHere .

最佳答案

请务必运行 latest version of androidx.test
如果您的测试一次运行一个,但同时运行时失败,Android Test Orchestrator (“ATO”)可以解决这个问题。
ATO 在新进程中运行每个测试方法,因此内存中的任何状态都被清除。
From the docs ,基本的gradle设置是:

android {
defaultConfig {
...
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// The following argument makes the Android Test Orchestrator run its
// "pm clear" command after each test invocation. This command ensures
// that the app's state is completely cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
}

testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}

dependencies {
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestUtil 'androidx.test:orchestrator:1.3.0'
}
文档还包括安装和使用设置 Android Test Orchestrator without gradle .
您还可以在 Firebase 测试实验室中使用 ATO:
  • via web UI
  • via CLI

  • 如果您的 IdlingResources 仍有问题,您可以尝试 busybee library这简化了 IdlingResources 的使用并使它们更易于调试。
    (免责声明,我是该库的维护者)

    关于android - registerIdlingResources 弃用替换不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46059677/

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