首页 > 解决方案 > gcloud CLI:如何使用 clearPackageData 参数运行仪器测试?

问题描述

我正在使用带有标志的gcloud firebase test android run命令运行我的测试,--use-orchestrator以启用 Android Test Orchestrator。一个 Orchestrator 参数clearPackageData可以在测试之间清除应用程序的状态,我可以在我自己的设备上从 Android Studio 运行测试时使用它:

android {
  defaultConfig {
   ...
   testInstrumentationRunner "android.support.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 'ANDROID_TEST_ORCHESTRATOR'
  }
}

dependencies {
  androidTestImplementation 'com.android.support.test:runner:1.0.2'
  androidTestUtil 'com.android.support.test:orchestrator:1.0.2'
}

但是,当使用上面提到的命令和标志在 Firebase 测试实验室中运行测试时,此参数设置为false. 有没有办法将此参数设置为true

标签: androidfirebaseandroid-testinggcloudfirebase-test-lab

解决方案


在 gcloud 命令行上使用它:

--environment-variables clearPackageData=true

推荐阅读