Andrii Abramov Andrii Abramov - 8 months ago 105
Android Question

Gradle: No tests found

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.

Answer Source

I find this confusing that this error is also shown when the exception is thrown in @BeforeClass method.

@RunWith(AndroidJUnit4.class)
public class DummyTest {

    @BeforeClass
    public static void setUpClass() {
        throw new RuntimeException("Dummy error");
    }

    @Test
    public void lalks() throws Exception {
        assertTrue(true);
    }
}

Output via adb:

Running tests

$ adb shell am instrument -w -r -e debug false -e class com.example.test.DummyTest com.example.test/android.support.test.runner.AndroidJUnitRunner
Client not ready yet..
Started running tests
Tests ran to completion.

Output via gradle:

Starting 1 tests on Nexus 5X - 7.1.1

junit.framework.TestSuite$1 > warning[Nexus 5X - 7.1.1] FAILED
        junit.framework.AssertionFailedError: No tests found in com.example.test.DummyTest
        at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:198)
:connectedAppDebugAndroidTest FAILED

If there is not exception thrown in @BeforeClass method everything will be fine.