Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 431
Sugre Avatar asked Jan 16 '15 03:01

Sugre


1 Answers

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'

like image 81
Nicolas Albert Avatar answered Nov 09 '22 01:11

Nicolas Albert