summaryrefslogtreecommitdiff
path: root/ravenwood
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@google.com>2023-12-06 15:22:11 -0700
committerJeff Sharkey <jsharkey@google.com>2023-12-07 08:54:27 -0700
commit9ac0521ccd1eb236ea3260f69d78e415c7ae1ae7 (patch)
tree11997fb9f56ce13de3d051a61afec80db9dd5e45 /ravenwood
parent7178e2b9a83422b173446e69d90c8750d654528a (diff)
downloadbase-9ac0521ccd1eb236ea3260f69d78e415c7ae1ae7.tar.gz
Ravenwood support for feature flags.
Since feature flags are becoming an important part of development work, ensure that Ravenwood tests can use existing tools such as `SetFlagsRule` to populate values for code-under-test to consume. To enable this, we extend `AndroidHeuristicsFilter` to recognize feature flags generated code, and include that in the Ravenwood environment by default. Bug: 311370221 Test: atest FrameworksCoreTestsRavenwood FrameworksCoreTests Change-Id: I526af65f816d153cb6e365cf6810a5a304d3e6a6
Diffstat (limited to 'ravenwood')
-rw-r--r--ravenwood/framework-minus-apex-ravenwood-policies.txt3
-rw-r--r--ravenwood/test-authors.md25
2 files changed, 26 insertions, 2 deletions
diff --git a/ravenwood/framework-minus-apex-ravenwood-policies.txt b/ravenwood/framework-minus-apex-ravenwood-policies.txt
index c9069e5db9cb..f5e4af50fc29 100644
--- a/ravenwood/framework-minus-apex-ravenwood-policies.txt
+++ b/ravenwood/framework-minus-apex-ravenwood-policies.txt
@@ -3,6 +3,9 @@
# Keep all AIDL interfaces
class :aidl stubclass
+# Keep all feature flag implementations
+class :feature_flags stubclass
+
# Collections
class android.util.ArrayMap stubclass
class android.util.ArraySet stubclass
diff --git a/ravenwood/test-authors.md b/ravenwood/test-authors.md
index 5adef534a2b2..de05777f01cd 100644
--- a/ravenwood/test-authors.md
+++ b/ravenwood/test-authors.md
@@ -71,10 +71,10 @@ public class MyCodeTest {
Once you’ve defined your test, you can use typical commands to execute it locally:
```
-$ atest MyTestsRavenwood
+$ atest --host MyTestsRavenwood
```
-> **Note:** There's a known bug where `atest` currently requires a connected device to run Ravenwood tests, but that device isn't used for testing.
+> **Note:** There's a known bug where `atest` currently requires a connected device to run Ravenwood tests, but that device isn't used for testing. Using the `--host` argument above is a way to bypass this requirement until bug #312525698 is fixed.
You can also run your new tests automatically via `TEST_MAPPING` rules like this:
@@ -89,6 +89,27 @@ You can also run your new tests automatically via `TEST_MAPPING` rules like this
}
```
+## Strategies for feature flags
+
+Ravenwood supports writing tests against logic that uses feature flags through the existing `SetFlagsRule` infrastructure maintained by the feature flagging team:
+
+```
+import android.platform.test.flag.junit.SetFlagsRule;
+
+@RunWith(AndroidJUnit4.class)
+public class MyCodeTest {
+ @Rule
+ public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
+
+ @Test
+ public void testEnabled() {
+ mSetFlagsRule.enableFlags(Flags.FLAG_MY_FLAG);
+ // verify test logic that depends on flag being enabled
+ }
+```
+
+This naturally composes together well with any `RavenwoodRule` that your test may need.
+
## Strategies for migration/bivalent tests
Ravenwood aims to support tests that are written in a “bivalent” way, where the same test code can run on both a real Android device and under a Ravenwood environment.