Have RequiredXxxRule's report ASSUMPTION_FAILED
Instead of just skipping and passing the tests
throw an AssumptionViolatedException so the CTS runner accounts
for the results properly
Bug: 152617516
Test: atest CtsContentSuggestionsTestCases
Change-Id: I46d9335cd2ab6ba903494356608e12cc397fd466
Merged-In: I46d9335cd2ab6ba903494356608e12cc397fd466
(cherry picked from commit b4f12ea85dcfb775e038a7f78fe7f0df2d4597dd)
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredFeatureRule.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredFeatureRule.java
index 44571d1..e80d69f 100644
--- a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredFeatureRule.java
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredFeatureRule.java
@@ -16,16 +16,22 @@
package com.android.compatibility.common.util;
+import static org.junit.Assume.assumeTrue;
+
import android.util.Log;
import androidx.test.InstrumentationRegistry;
+import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* Custom JUnit4 rule that does not run a test case if the device does not have a given feature.
+ *
+ * <p>The tests are skipped by throwing a {@link AssumptionViolatedException}. CTS test runners
+ * will report this as a {@code ASSUMPTION_FAILED}.
*/
public class RequiredFeatureRule implements TestRule {
private static final String TAG = "RequiredFeatureRule";
@@ -48,6 +54,8 @@
Log.d(TAG, "skipping "
+ description.getClassName() + "#" + description.getMethodName()
+ " because device does not have feature '" + mFeature + "'");
+ assumeTrue("Device does not have feature '" + mFeature + "'",
+ mHasFeature);
return;
}
base.evaluate();
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredServiceRule.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredServiceRule.java
index bbfa2db..2055327 100644
--- a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredServiceRule.java
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredServiceRule.java
@@ -16,17 +16,26 @@
package com.android.compatibility.common.util;
+import static org.junit.Assume.assumeTrue;
+
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.test.InstrumentationRegistry;
+import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
/**
* Custom JUnit4 rule that does not run a test case if the device does not have a given service.
+ *
+ * <p>The tests are skipped by throwing a {@link AssumptionViolatedException}. CTS test runners
+ * will report this as a {@code ASSUMPTION_FAILED}.
+ *
+ * <p><b>NOTE:</b> it must be used as {@code Rule}, not {@code ClassRule}.
+ *
*/
public class RequiredServiceRule implements TestRule {
private static final String TAG = "RequiredServiceRule";
@@ -52,6 +61,8 @@
Log.d(TAG, "skipping "
+ description.getClassName() + "#" + description.getMethodName()
+ " because device does not have service '" + mService + "'");
+ assumeTrue("Device does not have service '" + mService + "'",
+ mHasService);
return;
}
base.evaluate();
diff --git a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredSystemResourceRule.java b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredSystemResourceRule.java
index ead59943..0ddefa1 100644
--- a/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredSystemResourceRule.java
+++ b/common/device-side/util-axt/src/com/android/compatibility/common/util/RequiredSystemResourceRule.java
@@ -16,6 +16,8 @@
package com.android.compatibility.common.util;
+import static org.junit.Assume.assumeTrue;
+
import android.content.res.Resources;
import android.text.TextUtils;
import android.util.Log;
@@ -23,6 +25,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import org.junit.AssumptionViolatedException;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -30,6 +33,9 @@
/**
* Custom JUnit4 rule that does not run a test case if the device does not define the given system
* resource.
+ *
+ * <p>The tests are skipped by throwing a {@link AssumptionViolatedException}. CTS test runners
+ * will report this as a {@code ASSUMPTION_FAILED}.
*/
public class RequiredSystemResourceRule implements TestRule {
@@ -59,6 +65,8 @@
Log.d(TAG, "skipping "
+ description.getClassName() + "#" + description.getMethodName()
+ " because device does not have system resource '" + mName + "'");
+ assumeTrue("Device does not have system resource '" + mName + "'",
+ mHasResource);
return;
}
base.evaluate();