I am trying to run Instrumental tests for my project. But they do not work on devices (emulators) that have a version below 5 (API 21).
I am trying to solve this problem, but still run into it. I get the following exception.
02-15 10:46:08.965 1127-1143/? E/AndroidRuntime: FATAL EXCEPTION: Instr: android.support.test.runner.AndroidJUnitRunner
java.lang.ExceptionInInitializerError
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524)
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
Caused by: java.lang.NoClassDefFoundError: org.junit.runner.manipulation.Filter$1
at org.junit.runner.manipulation.Filter.<clinit>(Filter.java:21)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:81)
at android.support.test.internal.runner.TestRequestBuilder.<init>(TestRequestBuilder.java:524)
at android.support.test.runner.AndroidJUnitRunner.createTestRequestBuilder(AndroidJUnitRunner.java:379)
at android.support.test.runner.AndroidJUnitRunner.buildRequest(AndroidJUnitRunner.java:352)
at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:269)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1584)
I have already tried all the solutions for such issues.
This is what my project structure looks like.

And gradle dependencies for tests
androidTestCompile 'junit:junit:4.12'
androidTestCompile fileTree(include: ['robotium-solo-5.5.2.jar'], dir: 'libs')
androidTestCompile 'org.mockito:mockito-core:2.7.6'
androidTestCompile files('libs/dexmaker-mockito-1.0.jar')
androidTestCompile files('libs/dexmaker-1.0.jar')
androidTestCompile('com.android.support.test.espresso:espresso-core:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test:rules:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.android.support.test.espresso:espresso-intents:+') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile('com.squareup.okhttp3:mockwebserver:+') {
exclude module: 'okhttp'
}
androidTestCompile "org.slf4j:slf4j-api:1.7.12"
androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
exclude group: 'org.slf4j', module: 'slf4j-api'
exclude group: 'org.ow2.asm', module: 'asm'
exclude group: 'org.json', module: 'json'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
And BaseTestClasshave the following structure
@RunWith(AndroidJUnit4.class)
public abstract class InstrumentalSuperTest {
private SystemAnimations mSystemAnimations;
@Rule
public IntentsTestRule rule = provideActivity();
@Rule
public WireMockRule wireMockRule = new WireMockRule(WireMockConfiguration.wireMockConfig().port(BuildConfig.PORT), false);
protected abstract IntentsTestRule provideActivity();
}
And this happens not only with my project, but also with Wiremock examples , the same error.
Perhaps I am starting the test incorrectly, I just click on the test class and select Run ... Test.
Help solve this problem, I have no idea what is wrong.