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

Feature request - allow checking if activity is destroyed with ActivityScenario #235

Closed
ferinagy opened this issue Mar 8, 2019 · 0 comments
Assignees

Comments

@ferinagy
Copy link

ferinagy commented Mar 8, 2019

Description

We have an activity that immediately finishes (in onCreate()) if it does not receive correct intent arguments. I have found no way to test this with ActivityScenario. With ActivityTestRule we could do something like this:

val rule = ActivityTestRule(ExampleActivity::class.java, false, false)
rule.launchActivity(null)
assert(rule.activity.isDestroyed)

With ActivityScenario, the ActivityScenario.getCurrentActivityState() and connected methods are private, so I had to try something like:

val scenario = ActivityScenario.launch(ExampleActivity::class.java)
scenario.onActivity { assert(it.isDestroyed) }

But it fails with

java.lang.NullPointerException: Cannot run onActivity since Activity has been destroyed already
at androidx.test.internal.util.Checks.checkNotNull(Checks.java:41)
at androidx.test.core.app.ActivityScenario.lambda$onActivity$1$ActivityScenario(ActivityScenario.java:531)
at androidx.test.core.app.ActivityScenario$$Lambda$0.run(Unknown Source:4)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2163)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

It would be nice to provide a way to test use case like this. If you do not want to expose the getCurrentActivityState, maybe there could be at least something like ActivityScenario.isDestroyed()

AndroidX Test Versions

androidxTestMonitorVersion = '1.1.1'
androidxTestRulesVersion = '1.1.1'
androidxTestRunnerVersion = '1.1.1'
androidxTestJunitVersion = '1.1.0'

copybara-androidxtest pushed a commit that referenced this issue Mar 12, 2019
getState() API provides a way to check the current state of the activity under testing. This is especially useful when your activity redirects to another activity or finish itself during the launch.

FR: #235
PiperOrigin-RevId: 238095286
copybara-androidxtest pushed a commit that referenced this issue Mar 13, 2019
getState() API provides a way to check the current state of the activity under testing. This is especially useful when your activity redirects to another activity or finish itself during the launch.

FR: #235
PiperOrigin-RevId: 238095286
@yuuki3655 yuuki3655 self-assigned this Mar 13, 2019
copybara-androidxtest pushed a commit that referenced this issue Mar 13, 2019
getState() API provides a way to check the current state of the activity under testing. This is especially useful when your activity redirects to another activity or finish itself during the launch.

FR: #235
PiperOrigin-RevId: 238095286
copybara-androidxtest pushed a commit that referenced this issue Mar 13, 2019
getState() API provides a way to check the current state of the activity under testing. This is especially useful when your activity redirects to another activity or finish itself during the launch.

FR: #235
PiperOrigin-RevId: 238144049
rauljurado620 added a commit to rauljurado620/test-android-project that referenced this issue Mar 24, 2022
getState() API provides a way to check the current state of the activity under testing. This is especially useful when your activity redirects to another activity or finish itself during the launch.

FR: android/android-test#235
PiperOrigin-RevId: 238144049
Zemotacqy pushed a commit to Zemotacqy/android-test that referenced this issue May 5, 2023
Add SHA256 of android-test for Bazel to cache it properly.
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

2 participants