1

有谁知道一个示例项目,该项目展示了如何让测试协调器工作?我检查了谷歌示例,似乎没有一个很好的示例项目可以显示测试协调器。

https://github.com/googlesamples/android-testing

我一直试图让 android 测试在测试协调器中运行,但一直在努力让它正常工作。我尝试通过 Android Studio(最新 3.2.1)和命令行(https://developer.android.com/training/testing/junit-runner#ato-command-line)运行测试。我使用了 Android 开发者文档作为参考。

https://developer.android.com/training/testing/junit-runner

这是我遵循的步骤。

1) Create an empty activity application using the wizard in Android 
Studio 
2) Enable the test orchestrator using the steps provided here 
(https://developer.android.com/training/testing/junit-runner).
3) Run the unit tests from within the IDE and from the command line.

当我这样做时,我收到一个错误,表明我的“测试套件为空”。我从命令行运行时遇到同样的错误。

请注意,如果我在没有测试协调器的情况下运行测试,那么测试会成功运行。

另请注意,我使用的是最新的测试编排器版本

4

1 回答 1

3

运行测试编排器的完整配置:

  1. 添加依赖项:

    androidTestImplementation "androidx.test:runner:$testRunner" androidTestUtil "androidx.test:orchestrator:$testOrchestrator"

  2. 添加清除包指令(在应用程序的 build.gradle中的defaultConfig内):

    //允许以隔离方式运行所有测试。如果我们需要调试一个测试,应该禁用这个和编排器 testInstrumentationRunnerArguments clearPackageData: 'true'

  3. 添加到 testOptions Android/AndroidX 编排器:

    testOptions { 执行 'ANDROIDX_TEST_ORCHESTRATOR' }

于 2019-04-01T18:24:38.997 回答