31

When I am trying to run Android tests by executing:

./gradlew connectedDebugAndroidTest

The following error occurs:

com.android.builder.testing.ConnectedDevice > No tests found.[devicename] FAILED
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).
:connectedDebugAndroidTest FAILED

FAILURE: Build failed with an exception.

I have not made any changes to build.gradle or gradle-wrapper.properties files.

The issue can't be solved by updating everything to the latest version (gradle, android plugin, build tools, etc.)

All tests were previously successful. What could cause this mystic regression? Thanks.

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96

6 Answers6

68

One possible reason for this error message is that you get a crash in the app early in the test Runner. In such cases the exception stack will be in logcat but not in the gradle output.

miguel
  • 16,205
  • 4
  • 53
  • 64
6

I had the issue, try upgrading the test runner. Upgrading it to 0.5 from 0.4.x solved it. Ensure you have these lines in your build.gradle:

androidTestCompile "junit:junit:4.12"
androidTestCompile "com.android.support.test:runner:0.5"
jonduran
  • 61
  • 1
2

I faced this exact issue today. Please do feel free to use all the other worthy solutions as mentioned above but what specifically worked for me was to delete the ".gradle" folder (found under the project panel on the left in Android Studio) entirely, followed by a clean build. A simple clean build didn't work for me.

Sdr
  • 1,090
  • 9
  • 8
0

This can happen if the tests are placed in the test or androidTest directory without a package. The path should be something like /src/androidTest/kotlin/yourPackageName/yourTestClass.

Brian Bethke
  • 154
  • 6
0

You can check if individually, all tests pass. Could be some test(s) is(are) failing. Had a similar issue and that was my case

zeffah
  • 21
  • 4
-3

I solved this by deleting androidTests folders from unneeded modules - /common and /data in my case.