Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivityScenario hangs on EmptyActivity after testing activity with launchMode=singleInstance #1115

Open
jfresen opened this issue Sep 24, 2021 · 7 comments

Comments

@jfresen
Copy link

jfresen commented Sep 24, 2021

Description

When testing an Activity that has launchMode=singleInstance with an ActivityScenarioRule, after the test is completed the text executor gets stuck in EmptyActivity for ~45 seconds before progressing to the next test.

Steps to Reproduce

  • Create a new Android project in Android Studio using the project wizard, using e.g. the "Blank Activity" template.
  • Add android:launchMode="singleInstance" to the MainActivity's entry in AndroidManifest.xml
  • Add @get:Rule val rule = ActivityScenarioRule(MainActivity::class.java) to the ExampleInstrumentedTest
  • Run ExampleInstrumentedTest

Expected Results

Test runs and quits immediately after

Actual Results

Test runs and gets stuck in EmptyActivity for about ~45 seconds

AndroidX Test and Android OS Versions

androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

(physical) Pixel C, Android 8.1.0
(emulator) Pixel 2, API 30

@jfresen
Copy link
Author

jfresen commented Sep 24, 2021

@jfresen
Copy link
Author

jfresen commented Sep 24, 2021

Also, some commenters on #676 seem to be running into this issue. Indeed, when changing the launchMode to singleTask as per #676 (comment), the test terminates immediately after execution.

@tomcully
Copy link

I'm hitting this issue too in a compose app. One of the app dependencies requires the activity have a launchMode of "singleInstance" though so changing to singleTask is no good for us. Has anyone found a solution to this?

@jfresen
Copy link
Author

jfresen commented Feb 23, 2022

@brettchabot Do you have an idea what might be causing this?

@brettchabot
Copy link
Collaborator

@yuuki3655

@smascaro
Copy link

If it helps anyone, this is my workaround. It's definitely not a permanent solution, so if anyone has a better approach, feel free to share!

Basically, I detect based on the gradle tasks to be executed if we're running the ui tests. Then with this information I set a placeholder that will be used in the AndroidManifest.xml. The BuildConfig field is also useful if you need to, for example, involve IdlingResource in your non-test code.

def instrumentationTestTask = gradle.startParameter.taskNames.find { it == ":app:connectedDebugAndroidTest" }
if (instrumentationTestTask != null) {
    println "Building instrumentation APK"
    manifestPlaceholders += [activityLaunchMode: "singleTask"]
    buildConfigField "boolean", "INSTRUMENTATION_MODE", "true"
} else {
    manifestPlaceholders += [activityLaunchMode: "singleInstance"]
    buildConfigField "boolean", "INSTRUMENTATION_MODE", "false"
}
<activity
    ...
    android:launchMode="${activityLaunchMode}"
    ... />

@chrisjenx
Copy link

We tried both and it still hangs for a good 45 seconds, seems unrelated from what we can see, it is a lock in the getResult call from what we can see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants