Fix Espresso tests failing on #4692 - #4702
Conversation
|
Diagnosis on TabFragmentTest failures (By Copilot)
|
|
Fixes to BackupPrefsFragmentTest (By Copilot)
Copilot also reported a caveat that the test may still fail on API 21 devices, where legacy JAR verifier may be incompatible with modern APK signing on very old Android runtimes. |
There was a problem hiding this comment.
Pull request overview
Updates Android instrumentation (Espresso) tests to be more robust/reliable across API levels and lifecycle changes, addressing the Espresso failures reported in #4692 by moving away from deprecated ActivityTestRule, rotation hacks, and fixed sleeps.
Changes:
- Refactors
TabFragmentTestto useActivityScenario+scenario.recreate()and Awaitility-based polling instead of orientation changes and swipe actions. - Stabilizes
BackupPrefsFragmentTestby using the runtime external storage path, ensuring the activity isRESUMEDfor Espresso interactions, and polling for async file creation before asserting contents.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/src/androidTest/java/com/amaze/filemanager/ui/fragments/TabFragmentTest.kt | Reworks tab/state-saving tests to use ActivityScenario recreation and Awaitility waits instead of rotation/swipes. |
| app/src/androidTest/java/com/amaze/filemanager/ui/fragments/BackupPrefsFragmentTest.kt | Fixes export test flakiness by using dynamic storage path, correct lifecycle state for Espresso, and waiting for async file writes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
305019e to
feebe13
Compare
- TabFragmentTest use back actions to swipe instead of programmatically
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (3)
app/src/androidTest/java/com/amaze/filemanager/ui/fragments/TabFragmentTest.kt:167
awaitPager()callsscenario.onActivity {}inside an Awaitility polling loop without guarding againstIllegalStateExceptionduring activity recreation (e.g., afterrotateScreen). IfonActivitythrows while no Activity is in a valid state, Awaitility will fail the test immediately instead of retrying, making this flaky.
await().atMost(10, TimeUnit.SECONDS).until {
scenario.onActivity { activity ->
pager = activity.findViewById(R.id.pager)
}
app/src/androidTest/java/com/amaze/filemanager/ui/fragments/TabFragmentTest.kt:268
awaitOrientation()evaluatescurrentOrientation(scenario)inside Awaitility without catching exceptions. During rotation,ActivityScenario.onActivityinsidecurrentOrientation()can throw transiently while the Activity is being recreated, which can cause a hard test failure instead of letting Awaitility retry.
await().atMost(10, TimeUnit.SECONDS).until {
currentOrientation(scenario) == expectedOrientation
}
app/src/androidTest/java/com/amaze/filemanager/test/StoragePermissionHelper.kt:48
ActivityScenario.launch(MainActivity::class.java)is never closed. BecausegrantManageStoragePermission()is called from multiple@Beforemethods, this can leak Activities across tests and cause flakiness/interference. Prefer wrapping the launch + permission UI flow inActivityScenario.launch(...).use { ... }(ortry/finallywithscenario.close()) so the Activity is always torn down.
ActivityScenario.launch(MainActivity::class.java)
Description
Issue tracker
Addresses #4692
Automatic tests
Updated Espresso tests, no new tests added
Manual tests
Done
Device:
OS:
Build tasks success
Successfully running following tasks on local:
./gradlew assembledebug./gradlew spotlessCheckGenerative code
This PR used generative code tools (GenAI, LLMs, etc.)
Model: Claude Sonnet
Version: 4.6/5
Provider: Github Copilot
Related PR
Related to PR #4692