I run tests on multiple devices with ADB in parallel:
adb -s 11.11.11.111:5555 shell "CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.my.app.debug.test/androidx.test.runner.AndroidJUnitRunner -e clearPackageData true -e numShards 2 -e shardIndex 0 -e debug false androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator" &
adb -s 11.11.11.112:5555 shell "CLASSPATH=$(pm path androidx.test.services) app_process / androidx.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.my.app.debug.test/androidx.test.runner.AndroidJUnitRunner -e clearPackageData true -e numShards 2 -e shardIndex 1 -e debug false androidx.test.orchestrator/androidx.test.orchestrator.AndroidTestOrchestrator" &
wait
If a test fails, an error message / stacktrace is usually displayed, but not always. Therefore it would be helpful to save the logs of the app in a file. I tried the following command after the tests were finished:
adb -s 11.11.11.111:5555 logcat | grep "com.my.app.*" > app/build/reports/logcat.txt
But the command saves only the system logs in the file and not the logs which I can normally see when running the tests in Android Studio (in the logcat window of Android Studio).