【问题标题】:How to clean application data with 'pm clear' after each UI test每次 UI 测试后如何使用“pm clear”清理应用程序数据
【发布时间】:2020-07-30 07:07:30
【问题描述】:

我开始使用 Espresso Framework 和 UI Automator 在 android 中编写 UI 测试。

所以我编写了 3 个不同的 UI 测试,它们都包含身份验证过程。当我单独运行每个测试时,它们工作得很好。 但是,当我使用./gradlew connectedAndroidTest 运行所有 3 个测试时,第一个测试通过而其他 2 个测试失败,因为它自动登录(我使用 webview 登录,所以它会将我重定向到主屏幕)。我试过this solution,但没用。

我想要存档的是,在每次测试之后,使用清除数据 InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand("pm clean com.example.app") 并为每个测试重新开始。

当我在@After 中执行此操作时,测试会崩溃:

Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.''.

知道如何存档吗?

【问题讨论】:

    标签: android android-espresso android-uiautomator ui-testing


    【解决方案1】:

    我建议您使用Android Test Orchestrator,因为它会在单独的进程中运行每个测试,这意味着不会与其他测试共享任何状态或数据。

    【讨论】:

      猜你喜欢
      • 2015-11-27
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-02
      相关资源
      最近更新 更多