Sugre
Sugre

Reputation: 871

gradle connectedAndroidTest returns "No test found", however adb shell am instrument can find the tests

We have a library project and multiple applications depends on it. And the unit tests are in the library project. We're able to run the tests from dependent projects in Android Studio, but

./gradlew :[DependentProject]:connectedAndroidTest 

always returns "No test found, nothing to do”.

Through observation, I found in Android Studio, seems that it only executes gradle tasks:

:[DependentProject]:assembleDebug, :[DependentProject]assembleDebugTest

then uses adb to install the target and test apk, and adb shell am instruments to run the tests.

Since connectedAndroidTest depends on these two tasks, I install the target and test apks it produced, and manually invoked instrument command, tests got started.

adb shell am instrument -w com.package.test/android.test.InstrumentationTestRunner

Then the question comes, where does connectedAndroidTest look for tests, and why it cannot find the tests while adb instrument can? How to resolve this issue?

Upvotes: 9

Views: 2604

Answers (1)

Nicolas Albert
Nicolas Albert

Reputation: 2596

I have the same issue and I solve it by add a method starting with "test"

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

And all other method with @Test annotation work too !

Amazing no ? I found the answer here : No tests found with test runner 'JUnit 4'

Upvotes: 4

Related Questions