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

Attempt to configure androidTest to not keep activities and background/resume activities under test #17410

Open
mikehardy opened this issue Nov 10, 2024 · 4 comments
Labels
Dev Development, testing & CI Tests

Comments

@mikehardy
Copy link
Member

Can we configure androidTest to not keep activities and background/resume?

Note, this may not be possible / technically feasible. A quick exploratory attempt to configure an emulator programmatically (via adb?) to not keep activities is a first step. Then a load of one activity and background / resume cycle of that activity is a second step to see if it is even possible.

Would be an interesting way to surface these sorts of errors that happen semi-frequently where assumptions are made about activity (and now fragment) lifecycle in the face of need to re-construct activity

We have an "all activity load" type test that was meant to check for layout inflation issues, maybe that could be extended to not just load+inflate but also background the app while don't-keep-activities was set then foreground it again

Originally posted by @mikehardy in #17407 (comment)

@mikehardy
Copy link
Member Author

@lukstbit there is a way to do this programmatically, and it works on a real device apparently, but there is an upstream bug blocking it from taking effect (despite UI changing...) if you do it via adb:

adb shell settings put global always_finish_activities 1

https://issuetracker.google.com/issues/162006821#comment10

So it appears the only way to do this currently is to have a pre-test routine that opens settings and toggles it

  • adb shell settings put global development_settings_enabled 1
  • search for list item Don't Keep Activities and toggle it on

It does seem possible, and while it would be nice if these sorts of Activity lifecycle problems became fewer over the time, that hasn't been my experience. It seems that nearly every release turns some up

@mikehardy mikehardy added the Dev Development, testing & CI label Nov 12, 2024
@lukstbit
Copy link
Member

4+ years with that bug open doesn't sound too good...
We could use the UIAutomator to get around the bug and implement this. I played around a bit and did a test where DeckPicker is started put in the background and then again brought back. I made a gist for anyone interested. These tests would take quite some time to run from what I saw.

@mikehardy
Copy link
Member Author

Couldn't resist, just read through that. Obviously it's a hack but I love a functional hack that can be production-ized. This could be one...

I wonder though - what about the built-in stuff around Activity scenarios in the android test libraries?

https://developer.android.com/guide/components/activities/testing#recreate

@mikehardy
Copy link
Member Author

    java.lang.IllegalStateException: "Don't keep activities" developer options must be disabled for ActivityScenario

Ha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dev Development, testing & CI Tests
Projects
None yet
Development

No branches or pull requests

2 participants