I have an android project which contains 2 modules.
- Android Library Module
- Android Demo App Module for Library
I have setup required Test dependency, Gradle configuration same for both the project.
When I run a test from demo app it runs without any issue. But when the same sample test code run from a library module it can't able to find tests.
Here is the log I can see from the "Run" tab in an android studio.
Demo Module Test - Result
$ adb shell CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.cardstream.paymentdemo.test/androidx.test.runner.AndroidJUnitRunner -e debug false -e class 'com.cardstream.paymentdemo.ExampleInstrumentedTest' androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator
Client not ready yet..
Started running tests
Tests ran to completion.
Library Module Test - Result
$ adb shell CLASSPATH=$(pm path android.support.test.services) app_process / android.support.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.cardstream.payment.test/androidx.test.runner.AndroidJUnitRunner -e debug false -e class 'com.cardstream.payment.ExampleInstrumentedTest' android.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator
Client not ready yet..
Started running tests
Test running failed: No test results
Empty test suite.
From the above logs, I can see the difference in test services used by both modules.
Demo Module - androidx.test.services
Library Module - android.support.test.services
from the above observations, I have tried to covert those into similar behavior but unfortunately, I can't able to find any exact and valid answer or options.
Configuration for Instrumentation Runner for both module
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Few test dependencies for both module
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.1'
androidTestImplementation 'androidx.test:core:1.1.0'
androidTestImplementation 'androidx.test:core-ktx:1.1.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
I have created a new project with the library module and run the tests, it works fine for both modules(with support libraries).
I have migrated newly created project with AndroidX and then also works fine for both modules.
Hence, I am getting confused and can't able to figure out the solution for this situation as of now. I am looking forward to your help if anyone has any clues/suggestions/answers?