From 06e9c0001c772923d73cf813a89f2c28f3e63065 Mon Sep 17 00:00:00 2001 From: Junyu Lai Date: Wed, 12 Jul 2023 17:28:00 +0800 Subject: [PATCH] Install test app2 per test class for HostsideConnOnActivityStartTest With installing test apps per test class instead of test cases, the total execution time tests are improved from 1m56s to 1m34s in local trials. Notes: 1. This is a demonstration CL to other Hostside*Tests to show how to make app2 can be installed per test class. 2. The method that executed per test class should not shadow the method in the base class, see the doc of @BeforeClass. Test: atest HostsideConnOnActivityStartTest Bug: 289002798 Change-Id: Ia9875f0a9fdcb4fb4c55736034b56aad0491d451 --- .../net/HostsideConnOnActivityStartTest.java | 21 +++++++++++-------- .../cts/net/HostsideNetworkTestCase.java | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/tests/cts/hostside/src/com/android/cts/net/HostsideConnOnActivityStartTest.java b/tests/cts/hostside/src/com/android/cts/net/HostsideConnOnActivityStartTest.java index d11242584f..69eba418e9 100644 --- a/tests/cts/hostside/src/com/android/cts/net/HostsideConnOnActivityStartTest.java +++ b/tests/cts/hostside/src/com/android/cts/net/HostsideConnOnActivityStartTest.java @@ -18,21 +18,24 @@ package com.android.cts.net; import android.platform.test.annotations.FlakyTest; -import org.junit.After; -import org.junit.Before; +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.invoker.TestInformation; +import com.android.tradefed.testtype.junit4.AfterClassWithInfo; +import com.android.tradefed.testtype.junit4.BeforeClassWithInfo; + import org.junit.Test; public class HostsideConnOnActivityStartTest extends HostsideNetworkTestCase { private static final String TEST_CLASS = TEST_PKG + ".ConnOnActivityStartTest"; - @Before - public void setUp() throws Exception { - uninstallPackage(TEST_APP2_PKG, false); - installPackage(TEST_APP2_APK); + @BeforeClassWithInfo + public static void setUpOnce(TestInformation testInfo) throws Exception { + uninstallPackage(testInfo, TEST_APP2_PKG, false); + installPackage(testInfo, TEST_APP2_APK); } - @After - public void tearDown() throws Exception { - uninstallPackage(TEST_APP2_PKG, true); + @AfterClassWithInfo + public static void tearDownOnce(TestInformation testInfo) throws DeviceNotAvailableException { + uninstallPackage(testInfo, TEST_APP2_PKG, true); } @Test diff --git a/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java b/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java index 566d9da037..b89ab1f7b5 100644 --- a/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java +++ b/tests/cts/hostside/src/com/android/cts/net/HostsideNetworkTestCase.java @@ -46,7 +46,7 @@ abstract class HostsideNetworkTestCase extends BaseHostJUnit4Test { protected static final String TEST_APP2_APK = "CtsHostsideNetworkTestsApp2.apk"; @BeforeClassWithInfo - public static void setUpOnce(TestInformation testInfo) throws Exception { + public static void setUpOnceBase(TestInformation testInfo) throws Exception { DeviceSdkLevel deviceSdkLevel = new DeviceSdkLevel(testInfo.getDevice()); String testApk = deviceSdkLevel.isDeviceAtLeastT() ? TEST_APK_NEXT : TEST_APK; @@ -55,7 +55,8 @@ abstract class HostsideNetworkTestCase extends BaseHostJUnit4Test { } @AfterClassWithInfo - public static void tearDownOnce(TestInformation testInfo) throws DeviceNotAvailableException { + public static void tearDownOnceBase(TestInformation testInfo) + throws DeviceNotAvailableException { uninstallPackage(testInfo, TEST_PKG, true); }