将 InstrumentationTestRunner 和 AndroidJUnitRunner 与 Robotium 和 Espresso 一起使用

Use both InstrumentationTestRunner and AndroidJUnitRunner with Robotium and Espresso

我们使用带有 android.test.InstrumentationTestRunner 的 Robotium 进行测试。尽管如此,我们还是想用 Espresso 替换 Robotium,但我们对此仍有一些疑问,因为我们有一台带有 Jenkins 的机器用于 CI.

Espresso 使用 android.support.test.runner.AndroidJUnitRunner 而 Robotium 使用前面提到的,首先,我们希望能够同时使用这两个测试框架。 可能吗?我们如何在 build.gradle 文件中指定它?我们如何配置我们的 jenkins 机器以针对不同的测试框架执行不同的作业?

我知道可以让 Espresso 扩展 ActivityInstrumentationTestCase2,因为我们的 Robotium 测试 类 也使用从 ActivityInstrumentationTestCase2 扩展的测试运行器,但我们仍然需要解决instrumentation test runner的问题。

根据 Android 开发人员文档,AndroidJUnitRunner 替换了旧的 InstrumentationTestRunner 并启用了 JUnit 4 测试。

The AndroidJUnitRunner class is a JUnit test runner that lets you run JUnit 3 or JUnit 4-style test classes on Android devices, including those using the Espresso and UI Automator testing frameworks.

The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This class replaces the InstrumentationTestRunner class, which only supports JUnit 3 tests.

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

我没有找到很多能够 运行 仪器测试的例子(例如使用 Robotium)。我一直在寻找自己的目的。

该文档解释了如何在您的 build.gradle 文件中替换测试 运行ner https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests