Gradle connectedAndroidTest returns โ€œNo testโ€, however adb shell am tool can find tests

We have a library project, and many applications depend on it. And unit tests are in the library project. We can run tests from dependent projects in Android Studio, but

./gradlew :[DependentProject]:connectedAndroidTest 

always returns "No test, nothing to do."

Thanks to the observation I found in Android Studio, it seems that it only performs gradle tasks:

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

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

Since connectedAndroidTest depends on these two tasks, I install the target and test apk that he created, and the tool command is called manually, the tests started.

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

The question then becomes, where does connectAndroidTest look for tests and why can't it find tests while the adb tool can? How to solve this problem?

+8
android android-studio android-gradle gradle android-testing
source share
1 answer

I have the same problem and I solve it by adding a method starting with "test"

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

And all other methods using the @Test annotation too!

No wonder? I found the answer here: No tests found with test runner "JUnit 4"

+3
source share

All Articles