android / android/android-test

Got AssertionError while launching a activity by ActivityScenario.launch

Open
#1,199 27 comments 0 reactions 0 assignees View on GitHub
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
![image](https://user-images.githubusercontent.com/16262143/140885708-997af872-1327-4733-89a8-1099bc4ea6dc.png)
2. run test code
![image](https://user-images.githubusercontent.com/16262143/140886077-c109ba63-77d4-4977-96be-2186369f2ea7.png)
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.