bazelbuild / bazelbuild/rules_android
Alternative approach to run android instrumentation tests
- Dominant language
- Java
- Stars
- 203
- Forks
- 95
- PR merge metrics
- No merged PRs in 30d
Description
### Description of the problem / feature request:
An alternative approach to run Android Instrumentation tests.
Running the tests using `android_instrumentation_test` target has many issues and a bit complicated setup instructions
and compatibility issues (i.e, only on linux).
### Feature requests: what underlying problem are you trying to solve with this feature?
Even after following the instructions when I tried running the BasicSampleApp's instrumentation tests and it was working,
but It had some other issues too like the instrumentation tests don't work for the local adb (doesn't even install the test app)
But when I tried implementing the instrumentation tests for my project there were some more issues related to android-test repo when I was running the tests, and these issues were already filled long ago
- https://github.com/android/android-test/issues/682
- https://github.com/bazelbuild/bazel/issues/5876
Even if these issues are solved in android-test and bazel user might have to wait for a bazel release to do so
Then when I was trying to understand how the instrumentation tests work what I understood was the android_binary genarates the test apk and android_instrumentation_test only installs the test apk and runs the tests, with this idea I found a documentation that mentions we can run the instrumentation tests with just the test apk [through adb](https://developer.android.com/studio/test/command-line#AMSyntax)
With this I manually installed the test apk and the app using adb (found from bazel-bin), then ran the following command
```
adb shell am instrument -w /androidx.test.runner.AndroidJUnitRunner
```
I was able to run these tests perfectly and This might expand the compatibility to mac and windows too
This was quite simple but I didn't find it anywhere, so I just wanted to share it and maybe updating the documentation might be my first pull request in bazel
### What operating system are you running Bazel on?
Elementory OS (Ubuntu 18)
### What's the output of `bazel info release`?
release 4.1.0
### Have you found anything relevant by searching the web?
I did find the issue but there was no update in it
https://github.com/bazelbuild/bazel/issues/5876
### Any other information, logs, or outputs that you want to share?
*Running test on local device*
https://gist.github.com/FareesHussain/6c79e7172aff76135e77c6062a5ec134
*The similar error I face in my project*
https://gist.github.com/FareesHussain/ed7c3a56d8ba4a2f163583c52db25bb2
Contributor guide
Assessment
This issue has not been assessed yet.