【问题标题】:Reset/Clear App Before Each Instrumentation Test (Android Studio)在每次仪器测试之前重置/清除应用程序 (Android Studio)
【发布时间】:2019-05-18 09:00:32
【问题描述】:

我正在尝试执行一个测试套件,但我的研究需要在每次测试之前让应用程序处于清除状态。使用 Gradle 的 connectedCheck 应用程序只是在每次测试之前恢复,我使用 Orchestrator 将 clear 参数设置为 true 以便在测试后擦除数据,但如果我同时执行包中的所有测试,它表明该应用程序在执行之间并没有真正被清除。

您对我为什么可以在 android studio 或命令行上完成此操作有什么建议吗?

我也尝试过解决这个问题

  • 实现 ClearData 注释(不起作用)
  • 实现仅在第一次测试后执行的 clearData 任务

更新 显然我发现了问题所在 testInstrumentationRunnerArguments clearPackageData: 'true',我已将 Orchestrator 版本从 1.0.1 更新为 1.0.2,现在它可以工作了,在每次测试运行之前清除应用数据。

【问题讨论】:

  • adb -d uninstall "package.name" 应该删除与您的应用程序相关的所有内容。然后为您的软件包的新实例安装您的 APK。
  • 是的,这确实有效,但我可以使用它以便在每个测试类之间自动运行吗?
  • 如果您自己找到了答案,请考虑将其添加为该问题的答案。 (另见:Can I answer my own question?

标签: java android android-studio testing


【解决方案1】:

我已经通过更新 Orchestrator 版本解决了我的问题,如下所示:

build.gradle

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 {
    androidTestUtil 'com.android.support.test:orchestrator:1.0.2'

}

问题出在以前版本的 Orchestrator 上,1.0.1,不知道为什么。

【讨论】:

    猜你喜欢
    • 2021-04-25
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 2013-09-27
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    相关资源
    最近更新 更多