Google provide new classes to write tests for Android, and especially using jUnit 4: https://developer.android.com/tools/testing-support-library/index.html
I was wondering if it is possible to use the AndroidJUnit4 runner, as well as the Parameterized one, from jUnit?
The current accepted answer doesn't provide an explanation, and the linked example isn't great at showing what needs to be done. Here's a more complete explanation that will hopefully save someone from spending the time I did figuring this out.
While the documentation doesn't make this super obvious, it's actually surprisingly easy to set up! You are able to use another runner with instrumented Android tests as long as you set
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
in your modulebuild.gradle
file. If that is set, you do not need to explicitly set@RunWith(AndroidJUnit4.class)
in your instrumented tests.A minimal example would look like this:
build.gradle
:SampleParameterizedTest.java
:If you also have the need to run some tests individually and others parameterized in the same test class, see this answer on using the
Enclosed
runner: https://stackoverflow.com/a/35057629/1428743