“No tests found” for instrumentation tests for Lol

2019-04-04 17:53发布

问题:

My instrumentation based (espresso) tests don't run on Lollipop+ devices and emulators. They correctly run on any other platform. I have the same symptoms as the guy in this thread - https://groups.google.com/forum/?fromgroups#!topic/adt-dev/QW5SuzQizNk

  • My tests are in src/androidTest/java/
  • I've set testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
  • The test classes are @RunWith(AndroidJUnit4.class)
  • Individual tests are annotated with @Test

I can execute a ./gradlew connectedCheck and the tests run well on a device with KitKat, but when I try to run the same tests the same way on a device with Lollipop I get...

15:02:15.784 [WARN] [org.gradle.api.Task] Tests on XT1095 - 5.1 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'

15:02:16.011 [WARN] [org.gradle.api.Task] com.android.builder.testing.ConnectedDevice > No tests found.[XT1095 - 5.1] FAILED

15:02:16.011 [WARN] [org.gradle.api.Task] No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack @Test annotations).

回答1:

Finally it started working. I followed this answer: https://groups.google.com/d/msg/adt-dev/QW5SuzQizNk/mWdaEuuCCQAJ which links to: https://github.com/google/dagger/issues/271

Basically this was the problem:

I incorrectly used compile 'com.google.dagger:dagger-compiler:2.0.2'

instead of correct apt 'com.google.dagger:dagger-compiler:2.0.2'