Bazel + Android Studio + Robolectric + Espresso + Mockito + EasyMock/PowerMock
Name | Description |
---|---|
Bazel | Bazel build system |
Android SDK | Official SDK |
Android SDK Build Tools | Official Build Tools |
Android Studio or | Official IDE |
Intellij | Intellij IDE |
Name | Description |
---|---|
Espresso | Instrumentation Framework |
Robolectric | Unit Testing Framework |
- Import/Open this project with Android Studio/Intellij
- Install the Bazel plugin.
- In the project selection dialog, click "Import Bazel Project".
- For the project view, select "Create from scratch".
- Click "Finish".
This project builds with Bazel, Bazel's Android rules, and the Android Build tools.
Build the APK:
$ bazel build //src/main:template_app
Install the APK:
$ bazel mobile-install //src/main:template_app
or:
$ bazel build //src/main:template_app && adb install bazel-bin/src/main/template_app.apk
Run the App:
$ bazel mobile-install //src/main:template_app --start_app
Note: Expect the first build to take a few minutes, depending on your machine, because Bazel's cache is clean. After Bazel downloads and builds the app once, subsequent builds will be much faster.
Running the Unit Tests:
The Junit and Robolectric tests run on the JVM, no need for emulators or real devices.
$ bazel test //src/test:all
Run a single unit test (android_local_test
):
$ bazel test //src/test:play_services_utils_test
Get the list of all android_local_test
targets:
$ bazel query 'kind(android_local_test, //src/test/...)'
Running the Instrumentation Tests:
The Espresso instrumentation tests run on the device. There is no need to launch an emulator, Bazel will do it automatically as part of the instrumentation test.
This is currently only supported on Linux.
$ bazel test //src/androidTest:main_activity_test
Read the Bazel docs here.