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?