registerIdlingResources弃用替换不起作用

Cri*_*sic 19 android android-testing android-espresso

我正在尝试使用根据android文档的方法替换我的Espresso registerIdlingResourcesunregisterIdlingResources弃用方法IdlingRegistry.

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

我注意到旧版本(Espresso类)有一点不同,这一行在IdlingRegistry课堂上不存在:

baseRegistry.sync(IdlingRegistry.getInstance().getResources(), IdlingRegistry.getInstance().getLoopers());
Run Code Online (Sandbox Code Playgroud)

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

如何在没有这条线的情况下同步我的活套?

谢谢你的帮助.

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

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

yog*_*arl 0

确保运行最新版本androidx.test

如果您的测试一次运行一个,但一起运行时失败,Android Test Orchestrator(“ATO”)可以解决该问题。ATO 在新进程中运行每个测试方法,因此内存中的所有状态都会被清除。

从文档来看,基本的 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'
}
Run Code Online (Sandbox Code Playgroud)

该文档还包括在不使用 gradle 的情况下安装和使用Android Test Orchestrator的设置。

您还可以在 Firebase 测试实验室上使用 ATO:

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