Modern Apps git

← Modern-Apps.git

education: strengthen launch e2e test

Commit
e734b16f7ba64601ba113c6b675839ff6911bd2b
Author
Vayun Mathur <[email protected]>
When
2026-11-19 04:21 UTC (17 days ago)
Parents
478086a
Strengthen the single LaunchNoCrashTest for education instead of adding a
separate journey test, so the app keeps exactly one emulator e2e test.

The test now clears the target package data (pm clear) before the
grant/launch pass, so it starts from clean state on the emulator, then
performs one small deterministic core interaction after the existing
launch assertions: Learn catalog (with bundled Math subject) -> Settings action -> Parent settings (fresh install has no PIN, so no gate) -> Back -> Learn catalog. All selectors are verified literals from
the module's Compose code and strings (see the test body); no network,
accounts, Bluetooth, SIM, camera, microphone input or other hardware
dependency is introduced beyond the existing headless grant pass.

No production code, lint, detekt or test configuration was changed.

Verified compile-only (emulator runs centrally, not here):
JAVA_HOME=/home/vayun/maos/prebuilts/jdk/jdk21/linux-x86 ./gradlew
:education:assembleDev :education:assembleDevAndroidTest -- BUILD SUCCESSFUL.

Diff

education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt
diff --git a/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt b/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.ktindex c0ec6c162f..0552303ecc 100644--- a/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt+++ b/education/src/androidTest/java/com/vayunmathur/education/ui/LaunchNoCrashTest.kt@@ -23,6 +23,11 @@ import org.junit.runner.RunWith  * marker wait covers that load. A fresh install has a blank learner name, so  * the home title reads Learn.  *+ * Strengthened launch-e2e: clears the target package data before the+ * grant/launch pass so the journey starts from clean state, then performs+ * one small deterministic core interaction (see the test body) and returns+ * to the launch surface. Still a single @Test for this app.+ *  * UiDevice polling, not compose-test: compose's Espresso idle-sync reflects on  * hidden InputManager APIs that no longer exist on current releases, so every  * compose-rule test dies before its first line. Text polling works for Compose@@ -38,6 +43,10 @@ class LaunchNoCrashTest {         val targetContext = instrumentation.targetContext         val packageName = targetContext.packageName +        // Clean state first (fresh-install journey); grants follow the clear+        // because a clear can drop runtime-grant state on some releases.+        clearAppData(instrumentation.uiAutomation, packageName)+         grantAllRequestedPermissions(instrumentation.uiAutomation, targetContext.packageManager, packageName)          val intent = targetContext.packageManager.getLaunchIntentForPackage(packageName)@@ -55,10 +64,44 @@ class LaunchNoCrashTest {             "learn catalog never appeared; the app may have crashed on launch",             device.wait(Until.findObject(By.text(LEARN_TITLE)), CONTENT_TIMEOUT_MS),         )+        // Core interaction: with no PIN on a fresh install the Settings+        // action opens Parent settings directly (openParentArea); verify it,+        // then return to the catalog. Verified labels: Math is a bundled+        // subject header; Parent settings / Name are the parent surface.+        assertNotNull(+            "bundled Math subject never appeared on the catalog",+            device.wait(Until.findObject(By.text(MATH_SUBJECT)), CONTENT_TIMEOUT_MS),+        )+        val settings = device.wait(Until.findObject(By.desc(SETTINGS_DESC)), CONTENT_TIMEOUT_MS)+        assertNotNull("Settings action never appeared on the catalog", settings)+        settings!!.click()+        assertNotNull(+            "parent settings never appeared",+            device.wait(Until.findObject(By.text(PARENT_TITLE)), CONTENT_TIMEOUT_MS),+        )+        assertNotNull(+            "learner Name field never appeared in parent settings",+            device.wait(Until.findObject(By.text(NAME_LABEL)), CONTENT_TIMEOUT_MS),+        )+        device.pressBack()+        assertNotNull(+            "learn catalog never reappeared after Back",+            device.wait(Until.findObject(By.text(LEARN_TITLE)), CONTENT_TIMEOUT_MS),+        )         // Still alive in front: the process did not crash after painting content.         assertEquals(packageName, device.currentPackageName)     } +    private fun clearAppData(uiAutomation: UiAutomation, packageName: String) {+        try {+            uiAutomation.executeShellCommand("pm clear $packageName").close()+        } catch (ignored: SecurityException) {+            // Clear refused: the journey assertions below still report state.+        } catch (ignored: IOException) {+            // Shell pipe failed: the content assertions below report it.+        }+    }+     private fun grantAllRequestedPermissions(         uiAutomation: UiAutomation,         packageManager: PackageManager,@@ -95,6 +138,10 @@ class LaunchNoCrashTest {         private const val GATE_TIMEOUT_MS = 5_000L         private const val LEARN_TITLE = "Learn"         private const val PERMISSION_GATE_TITLE = "Grant Required Permissions"+        private const val MATH_SUBJECT = "Math"+        private const val SETTINGS_DESC = "Settings"+        private const val PARENT_TITLE = "Parent settings"+        private const val NAME_LABEL = "Name"          /**          * Special access behind some apps' gates: exact alarms + full-screen intent