8

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?

Sugre
  • 851
  • 2
  • 9
  • 19
  • When I get the no tests found error, oftentimes unplugging and replugging the device will fix it. (lame, but that's just what I've observed) – CasualT Aug 14 '15 at 18:15
  • also, we run all the builds for our multi-library project with the command 'gradle connectedCheck' – CasualT Aug 14 '15 at 18:17
  • Can you post your Gradle build configuration? Have you got a block defining where you tests and java are? : sourceSets { main {....} androidTest {.....} } – Scott Oct 01 '15 at 08:04
  • Do you have proguard enabled for instrumented tests? – Daniel Gomez Rico Nov 17 '18 at 15:18

1 Answers1

3

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'

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Nicolas Albert
  • 2,586
  • 1
  • 16
  • 16
  • I remember that it's true that our tests don't start with "test", so that might be the reason, however I no longer have access to the code..... I thought for junit4 @Test annotation should be enough, but it seems not. Thank you. – Sugre Feb 11 '16 at 15:58
  • Still, I'm not sure why those tests can be located by "adb shell am instrument" in my case, that may remain a mystery for a while... – Sugre Feb 11 '16 at 16:00