Add connectivity coverage tests
The coverage tests will allow measuring code coverage for all
Connectivity+Tethering code.
This is a combination of the current TetheringCoverageTests, and
FrameworksNetTests.
Adding min_sdk_version to the test prevents it from using deprecated
IoUtils utilities. Replace it with the non-deprecated alternative.
Test: atest ConnectivityCoverageTests
Change-Id: I5366e1cc9cd6ddb41f24718246381cc2b1cc1383
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 5eb43f3..a7f57e8 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -45,21 +45,21 @@
],
}
-android_test {
- name: "FrameworksNetTests",
+android_library {
+ name: "FrameworksNetTestsLib",
+ min_sdk_version: "30",
defaults: [
"framework-connectivity-test-defaults",
- "FrameworksNetTests-jni-defaults",
],
srcs: [
"java/**/*.java",
"java/**/*.kt",
],
- test_suites: ["device-tests"],
jarjar_rules: "jarjar-rules.txt",
static_libs: [
"androidx.test.rules",
"bouncycastle-repackaged-unbundled",
+ "core-tests-support",
"FrameworksNetCommonTests",
"frameworks-base-testutils",
"frameworks-net-integration-testutils",
@@ -78,7 +78,21 @@
"android.test.mock",
"ServiceConnectivityResources",
],
+ visibility: ["//packages/modules/Connectivity/tests:__subpackages__"],
+}
+
+android_test {
+ name: "FrameworksNetTests",
+ min_sdk_version: "30",
+ defaults: [
+ "framework-connectivity-test-defaults",
+ "FrameworksNetTests-jni-defaults",
+ ],
+ test_suites: ["device-tests"],
+ static_libs: [
+ "FrameworksNetTestsLib",
+ ],
jni_libs: [
"libservice-connectivity",
- ],
+ ]
}
diff --git a/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java b/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java
index 93599f3..40d4446 100644
--- a/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java
+++ b/tests/unit/java/com/android/server/net/NetworkStatsFactoryTest.java
@@ -43,10 +43,10 @@
import androidx.test.runner.AndroidJUnit4;
import com.android.frameworks.tests.net.R;
-import com.android.internal.util.test.FsUtil;
import libcore.io.IoUtils;
import libcore.io.Streams;
+import libcore.testing.io.TestIoUtils;
import org.junit.After;
import org.junit.Before;
@@ -70,10 +70,7 @@
@Before
public void setUp() throws Exception {
- mTestProc = new File(InstrumentationRegistry.getContext().getFilesDir(), "proc");
- if (mTestProc.exists()) {
- FsUtil.deleteContents(mTestProc);
- }
+ mTestProc = TestIoUtils.createTemporaryDirectory("proc");
// The libandroid_servers which have the native method is not available to
// applications. So in order to have a test support native library, the native code
@@ -86,10 +83,6 @@
@After
public void tearDown() throws Exception {
mFactory = null;
-
- if (mTestProc.exists()) {
- FsUtil.deleteContents(mTestProc);
- }
}
@Test
diff --git a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
index 3dd6598..ee94ae9 100644
--- a/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
+++ b/tests/unit/java/com/android/server/net/NetworkStatsServiceTest.java
@@ -118,12 +118,13 @@
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.test.BroadcastInterceptingContext;
-import com.android.internal.util.test.FsUtil;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings;
import com.android.server.net.NetworkStatsService.NetworkStatsSettings.Config;
import com.android.testutils.HandlerUtils;
import com.android.testutils.TestableNetworkStatsProviderBinder;
+import libcore.testing.io.TestIoUtils;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
@@ -238,10 +239,7 @@
MockitoAnnotations.initMocks(this);
final Context context = InstrumentationRegistry.getContext();
mServiceContext = new MockContext(context);
- mStatsDir = context.getFilesDir();
- if (mStatsDir.exists()) {
- FsUtil.deleteContents(mStatsDir);
- }
+ mStatsDir = TestIoUtils.createTemporaryDirectory(getClass().getSimpleName());
PowerManager powerManager = (PowerManager) mServiceContext.getSystemService(
Context.POWER_SERVICE);
@@ -310,8 +308,6 @@
@After
public void tearDown() throws Exception {
- FsUtil.deleteContents(mStatsDir);
-
mServiceContext = null;
mStatsDir = null;