summaryrefslogtreecommitdiff
path: root/ravenwood/junit-src
diff options
context:
space:
mode:
author Makoto Onuki <omakoto@google.com> 2024-02-01 09:42:37 -0800
committer Makoto Onuki <omakoto@google.com> 2024-02-01 13:12:58 -0800
commit03e9c7c4c6cba06df4a4e814757eae6aed1b0fb5 (patch)
treebf793cd753bb7b879de96aa02ae594057afbf9ff /ravenwood/junit-src
parentbdf038d5959d6ba4b2e79f5be3afa16a48bcdc08 (diff)
Preparing to switch away from the deprecated test runner
A lot of ravenwood tests (and other tests too) use the deprecated test runner androidx.test.runner.AndroidJUnit4, but it actually has problems. We should switch them to androidx.test.ext.junit.runners.AndroidJUnit4. However, simply updating all tests could be problematic because: - we need to update the build rules and add "androidx.test.ext.junit" as a static dependency, which is probably safe but it could cause class conflicts.(?) - More importantly, the subtle difference between the test runner could make the device side test fail. So I'm going to do it in two steps: - Step 1 -- this CL: Add an optional validator to RavenwoodTest, which can be enabled with RAVENWOOD_OPTIONAL_VALIDATION=1. This makes a test fail if it's using the deprecated one. - Added a test for this - Added a script to replace the test runner. Test: run-ravenwood-tests Test: RAVENWOOD_OPTIONAL_VALIDATION=1 atest RavenwoodCoreTest Bug: 317131861 Change-Id: I5762bd097c3a529ae6e14460d9e326ed5c6086b4
Diffstat (limited to 'ravenwood/junit-src')
-rw-r--r--ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java25
1 files changed, 21 insertions, 4 deletions
diff --git a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
index daed457fb695..764573defd7a 100644
--- a/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
+++ b/ravenwood/junit-src/android/platform/test/ravenwood/RavenwoodRule.java
@@ -89,6 +89,12 @@ public class RavenwoodRule implements TestRule {
private static final boolean ENABLE_REALLY_DISABLE_PATTERN =
!REALLY_DISABLE_PATTERN.pattern().isEmpty();
+ /**
+ * If true, enable optional validation on running tests.
+ */
+ private static final boolean ENABLE_OPTIONAL_VALIDATION = "1".equals(
+ System.getenv("RAVENWOOD_OPTIONAL_VALIDATION"));
+
static {
if (ENABLE_PROBE_IGNORED) {
System.out.println("$RAVENWOOD_RUN_DISABLED_TESTS enabled: force running all tests");
@@ -275,6 +281,12 @@ public class RavenwoodRule implements TestRule {
}
}
+ private void commonPrologue(Statement base, Description description) {
+ RavenwoodRuleImpl.logTestRunner("started", description);
+ RavenwoodRuleImpl.validate(base, description, ENABLE_OPTIONAL_VALIDATION);
+ RavenwoodRuleImpl.init(RavenwoodRule.this);
+ }
+
/**
* Run the given {@link Statement} with no special treatment.
*/
@@ -284,8 +296,7 @@ public class RavenwoodRule implements TestRule {
public void evaluate() throws Throwable {
Assume.assumeTrue(shouldEnableOnRavenwood(description));
- RavenwoodRuleImpl.logTestRunner("started", description);
- RavenwoodRuleImpl.init(RavenwoodRule.this);
+ commonPrologue(base, description);
try {
base.evaluate();
RavenwoodRuleImpl.logTestRunner("finished", description);
@@ -310,8 +321,7 @@ public class RavenwoodRule implements TestRule {
public void evaluate() throws Throwable {
Assume.assumeFalse(shouldStillIgnoreInProbeIgnoreMode(description));
- RavenwoodRuleImpl.logTestRunner("started", description);
- RavenwoodRuleImpl.init(RavenwoodRule.this);
+ commonPrologue(base, description);
try {
base.evaluate();
} catch (Throwable t) {
@@ -331,4 +341,11 @@ public class RavenwoodRule implements TestRule {
}
};
}
+
+ /**
+ * Do not use it outside ravenwood core classes.
+ */
+ public boolean _ravenwood_private$isOptionalValidationEnabled() {
+ return ENABLE_OPTIONAL_VALIDATION;
+ }
}