We're using Robotium with the android.test.InstrumentationTestRunner
for our tests. Nevertheless we want to replace Robotium for Espresso, but we still have some doubts about it, since we have a machine with Jenkins for the CI.
Espresso uses the android.support.test.runner.AndroidJUnitRunner
while Robotium uses the aforementioned and first, we would like to be able to use both testing frameworks at the same time.
Is it possible? How can we specify that in the build.gradle
file? How can we configure our jenkins machine to have different jobs for the different testing frameworks?
I understand it is possible to have Espresso extend the ActivityInstrumentationTestCase2
, since our Robotium test classes also use a test runner which extends from ActivityInstrumentationTestCase2
, but we still need to tackle the problem of the instrumentation test runner.
Why do you use the AndroidJUnitRunner when running UI tests? The test runner facilitates loading your test package and the app under test onto a device or emulator, runs the test, and reports the results.
Earlier in the module's build.gradle file, we have a testInstrumentationRunner statement: testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" (from ToDoTests/build.gradle) This tells Android how to run our JUnit instrumented tests. JUnit uses “runner” classes for this role, and androidx.
From the Android developer docs, AndroidJUnitRunner
replaces the older InstrumentationTestRunner
and enables JUnit 4 tests.
The
AndroidJUnitRunner
class is aJUnit
test runner that lets you runJUnit 3
orJUnit 4
-style test classes on Android devices, including those using theEspresso
andUI 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
I've not found many examples of being able to run Instrumentation Tests (e.g. using Robotium). I've been looking for my own purposes.
The doc explains how to replace the test runner in your build.gradle
file https://developer.android.com/training/testing/unit-testing/instrumented-unit-tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With