From da51eb327c39b64357faa85ce5c884d51a58c003 Mon Sep 17 00:00:00 2001 From: dannark Date: Thu, 22 Feb 2018 18:29:57 -0800 Subject: Enable ability to pass the resource apk to Robolectric so that it can consume binary resources. This functionality is guarded by a flag, --experimental_android_local_test_binary_resources whose default value is false. If the flag is set to true, Bazel will generate the .ap_ and add the path to the .ap_ to the test_config.properties file. Bazel will still generate and pass the raw resources to Robolectric in both cases and so the cue to Robolectric that binary resources should be used is the presence of the path to the .ap_ in the test_config.properties file. RELNOTES: None PiperOrigin-RevId: 186708941 --- .../lib/rules/android/AndroidLocalTestTest.java | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestTest.java index 34583b7dea..9095676700 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidLocalTestTest.java @@ -130,6 +130,37 @@ public abstract class AndroidLocalTestTest extends AbstractAndroidLocalTestTestB MoreAsserts.assertContainsSublist(args, "--packageForR", "custom.pkg"); } + @Test + public void testBinaryResources() throws Exception { + scratch.file( + "java/test/BUILD", + "load('//java/bar:foo.bzl', 'extra_deps')", + "android_local_test(name = 'dummyTest',", + " srcs = ['test.java'],", + " deps = extra_deps)"); + useConfiguration("--experimental_android_local_test_binary_resources"); + ConfiguredTarget target = getConfiguredTarget("//java/test:dummyTest"); + Iterable runfilesArtifacts = collectRunfiles(target); + Artifact resourceApk = + ActionsTestUtil.getFirstArtifactEndingWith(runfilesArtifacts, "dummyTest.ap_"); + assertThat(resourceApk).isNotNull(); + } + + @Test + public void testNoBinaryResources() throws Exception { + scratch.file( + "java/test/BUILD", + "load('//java/bar:foo.bzl', 'extra_deps')", + "android_local_test(name = 'dummyTest',", + " srcs = ['test.java'],", + " deps = extra_deps)"); + ConfiguredTarget target = getConfiguredTarget("//java/test:dummyTest"); + Iterable runfilesArtifacts = collectRunfiles(target); + Artifact resourceApk = + ActionsTestUtil.getFirstArtifactEndingWith(runfilesArtifacts, "dummyTest.ap_"); + assertThat(resourceApk).isNull(); + } + @Override protected String getRuleName() { return "android_local_test"; -- cgit v1.2.3