Gradle: no tests found

When I try to run Android tests by doing:

./gradlew connectedDebugAndroidTest

The following error has occurred:

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 did not make any changes to the files build.gradleor gradle-wrapper.properties.

The problem cannot be solved by updating everything to the latest version (gradle, android plugin, build tools, etc.)

All tests have been successful previously. What can cause this mystical regression? Thank.

+9
source share
4 answers

, Runner. logcat, gradle.

+13

, , @BeforeClass.

@RunWith(AndroidJUnit4.class)
public class DummyTest {

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

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

adb:

$ 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.

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

@BeforeClass, .

-1

, . 0,5 0,4%, . , build.gradle:

androidTestCompile "junit:junit:4.12"
androidTestCompile "com.android.support.test:runner:0.5"
+4

I ran into this problem today. Please feel free to use all the other decent solutions as mentioned above, but what I especially liked was to completely delete the ".gradle" folder (located under the project panel on the left in Android Studio) and then do a clean build. A simple clean build did not work for me.

0
source

Source: https://habr.com/ru/post/1673281/


All Articles