android / android/android-test
Got AssertionError while launching a activity by ActivityScenario.launch
- Dominant language
- Java
- Stars
- 1.2k
- Forks
- 342
- Avg merge
- 11h 29m
- Merged PRs (30d)
- 2
Description
### Description
Got Error messages as below:
java.lang.AssertionError: Activity never becomes requested state "[CREATED, DESTROYED, RESUMED, STARTED]" (last lifecycle transition = "PRE_ON_CREATE") at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:338)
some message shows in log
E/TestRunner( 3422): ----- begin exception -----
E/TestRunner( 3422): java.lang.AssertionError: Activity never becomes requested state "[RESUMED, CREATED, DESTROYED, STARTED]" (last lifecycle transition = "PRE_ON_CREATE")
E/TestRunner( 3422): at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:338)
E/TestRunner( 3422): at androidx.test.core.app.ActivityScenario.launchInternal(ActivityScenario.java:272)
E/TestRunner( 3422): at androidx.test.core.app.ActivityScenario.launch(ActivityScenario.java:226)
### Steps to Reproduce
1. assign a different process name to the test activity (not a launcher category) in AndroidManifest.xml

2. run test code

3. The activity UI shows on screen but can't be operated by onView and then it shows the error after a few seconds.
### AndroidX Test and Android OS Versions
OS version: android 10
androidx.test.espresso core: 3.4.0
androidx.test.rule: 1.4.0
### workaround solution ###
don't give android:process name to the test activity
Contributor guide
Research direction
Start with ActivityScenario.launchInternal and waitForActivityToBecomeAnyOf at the stack-trace locations, then reproduce the case using an AndroidManifest.xml test activity assigned to a different process. Compare the lifecycle transitions with the activity that appears on screen; done means ActivityScenario.launch completes and onView can operate the activity without the assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100