Address Brett's comments
1 file changed
tree: 7e4a102feeec5ccc042b90e6968df3e0266d3a22
  1. bazel/
  2. README.md
  3. WORKSPACE
README.md

robolectric-bazel

This project provides build rules for integrating Robolectric into Bazel projects.

Usage

Add the robolectric and rules_jvm_external repositories in your WORKSPACE file:

http_archive(
    name = "robolectric",
    urls = ["https://github.com/robolectric/robolectric-bazel/archive/4.1.tar.gz"],
    strip_prefix = "robolectric-bazel-4.1",
)
load("@robolectric//bazel:robolectric.bzl", "robolectric_repositories")
robolectric_repositories()

http_archive(
    name = "rules_jvm_external",
    strip_prefix = "rules_jvm_external-1.1"
    url = "https://github.com/bazelbuild/rules_jvm_external/archive/1.1.zip",
)
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
    artifacts = [
        "org.robolectric:robolectric:4.1",
    ],
    repositories = [
        "https://maven.google.com",
        "https://repo1.maven.org/maven2",
    ],
)

Then, in your android_local_test targets in the BUILD files, depend on the Robolectric targets @maven//:org_robolectric_robolectric and @robolectric//bazel:android-all:

android_local_test(
    name = "greeter_activity_test",
    srcs = ["GreeterTest.java"],
    manifest = "TestManifest.xml",
    test_class = "com.example.bazel.GreeterTest",
    deps = [
        ":greeter_activity",
        "@maven//:org_robolectric_robolectric",
        "@robolectric//bazel:android-all",
    ],
)