From 78fcfdb7c86ff1625415d0fa0a5735565c8a7e41 Mon Sep 17 00:00:00 2001 From: Aaron Huang Date: Tue, 11 Oct 2022 11:38:05 +0800 Subject: [PATCH] Skip test if battery is not present The battery stats won't be updated if the device has no battery which causes the test failed. Thus the test should be skipped if the device has no battery. Bug: 245075045 Test: Build Change-Id: I0ae1e030c7e178ced91c94a8bc65a1d279ba37b3 --- tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java b/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java index 6b2a1ee4c2..e2821cb843 100644 --- a/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java +++ b/tests/cts/net/src/android/net/cts/BatteryStatsManagerTest.java @@ -21,12 +21,14 @@ import static android.content.pm.PackageManager.FEATURE_TELEPHONY; import static androidx.test.InstrumentationRegistry.getContext; +import static com.android.compatibility.common.util.BatteryUtils.hasBattery; import static com.android.compatibility.common.util.SystemUtil.runShellCommand; import static com.android.testutils.MiscAsserts.assertThrows; import static com.android.testutils.TestPermissionUtil.runAsShell; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import android.content.Context; import android.content.pm.PackageManager; @@ -97,6 +99,7 @@ public class BatteryStatsManagerTest{ @RequiresDevice // Virtual hardware does not support wifi battery stats public void testReportNetworkInterfaceForTransports() throws Exception { try { + assumeTrue("Battery is not present. Ignore test.", hasBattery()); // Simulate the device being unplugged from charging. executeShellCommand("cmd battery unplug"); executeShellCommand("cmd battery set status " + BATTERY_STATUS_DISCHARGING);