From 08f5b594825364df3043d9f6b12a48e1eb8630a8 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Mon, 22 Apr 2024 17:03:58 +0800 Subject: [PATCH] Assert fixed test method count in ConnectivityServiceTest ConnectivityServiceTest is deprecated but people sometimes still add new test methods to it, and getting review feedback to rewrite tests in CSTest. This wastes resources. Thus, assert fixed test method count to make it fails locally for people to aware of it. Test: atest ConnectivityCoverageTests:android.net.connectivity.com.android.server.ConnectivityServiceTest#testTestMethodCount Bug: N/A Change-Id: I0a98a0e3fcd97484f372737e7c6fe24743c21834 --- .../server/ConnectivityServiceTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/unit/java/com/android/server/ConnectivityServiceTest.java b/tests/unit/java/com/android/server/ConnectivityServiceTest.java index ce495335b5..f9a35fe6eb 100755 --- a/tests/unit/java/com/android/server/ConnectivityServiceTest.java +++ b/tests/unit/java/com/android/server/ConnectivityServiceTest.java @@ -457,6 +457,7 @@ import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.Method; import java.net.DatagramSocket; import java.net.Inet4Address; import java.net.Inet6Address; @@ -19188,6 +19189,25 @@ public class ConnectivityServiceTest { verifyClatdStop(null /* inOrder */, MOBILE_IFNAME); } - // Note : adding tests is ConnectivityServiceTest is deprecated, as it is too big for + private static final int EXPECTED_TEST_METHOD_COUNT = 332; + + @Test + public void testTestMethodCount() { + final Class testClass = this.getClass(); + + int actualTestMethodCount = 0; + for (final Method method : testClass.getDeclaredMethods()) { + if (method.isAnnotationPresent(Test.class)) { + actualTestMethodCount++; + } + } + + assertEquals("Adding tests in ConnectivityServiceTest is deprecated, " + + "as it is too big for maintenance. Please consider adding new tests " + + "in subclasses of CSTest instead.", + EXPECTED_TEST_METHOD_COUNT, actualTestMethodCount); + } + + // Note : adding tests in ConnectivityServiceTest is deprecated, as it is too big for // maintenance. Please consider adding new tests in subclasses of CSTest instead. }