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 "close()" doesn't work as expected #2111

Open
gustavobarbosab opened this issue Jan 19, 2024 · 3 comments
Open

ActivityScenario "close()" doesn't work as expected #2111

gustavobarbosab opened this issue Jan 19, 2024 · 3 comments

Comments

@gustavobarbosab
Copy link

gustavobarbosab commented Jan 19, 2024

Description

I'm running an instrumented test using ActivityScenario, so I launch the test, and after the test finishes, I call the method close() of the ActivityScenario.

Then, I received the following error:

java.lang.AssertionError: Activity never becomes requested state "[DESTROYED]" (last
                  lifecycle transition = "RESUMED")
                  	at androidx.test.core.app.ActivityScenario.waitForActivityToBecomeAnyOf(ActivityScenario.java:449)
                  	at androidx.test.core.app.ActivityScenario.moveToState(ActivityScenario.java:684)
                  	at androidx.test.core.app.ActivityScenario.close(ActivityScenario.java:416)
                  	at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:59)
                  	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                  	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
                  	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
                  	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
                  	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
                  	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
                  	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                  	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
                  	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                  	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
                  	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                  	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
                  	at org.junit.runners.Suite.runChild(Suite.java:128)
                  	at org.junit.runners.Suite.runChild(Suite.java:27)
                  	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
                  	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
                  	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
                  	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
                  	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
                  	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
                  	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
                  	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
                  	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
                  	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:67)
                  	at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
                  	at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:446)
                  	at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2218)

I don't know exactly why, but every time that I move the scenario to state DESTROYED the test crashes with the exception above.
When I remove the method "close" calling, the test starts to work as expected.

Steps to Reproduce

  • Create an instrumented test for an Activity
  • Starts the test using the method "ActivityScenario.launch"
  • Closes the scenario using an "@after" JUnit annotation
  • The crash will happen

Some libraries used:

  • Mockk
  • An abstraction of MockWebServer

Expected Results

  • Test pass without problems

Actual Results

  • Test crashing when calling close method.

AndroidX Test and Android OS Versions

MacBook Pro Apple M1 Pro
OS: Ventura 13.5
JDK version: java 17.0.8
Gradle version: 8.5
AGP: 8.2.1
AndroidX core library version: 1.5.0
Emulator: Pixel 4 API 33

Link to a public git repo demonstrating the problem:

@gustavobarbosab gustavobarbosab changed the title ActivityScenario "close()" doesn ActivityScenario "close()" doesn't work correctly Jan 19, 2024
@gustavobarbosab gustavobarbosab changed the title ActivityScenario "close()" doesn't work correctly ActivityScenario "close()" doesn't as expected Jan 19, 2024
@gustavobarbosab gustavobarbosab changed the title ActivityScenario "close()" doesn't as expected ActivityScenario "close()" doesn't work as expected Jan 19, 2024
@pedrofsn
Copy link

Up!

@brettchabot
Copy link
Collaborator

Can you provide a code sample that repros the problem

@gustavobarbosab
Copy link
Author

@brettchabot I have these tests in a private project, but I'm creating an open-source project to exemplify it and reproduce the error.

I have tried a lot of changes to understand why the error is happening, but I wasn't able. If I use the deprecated ActivityTestRule the test is executed successfully, but when using ActivityScenario the error happens in the moment that I call the method close.

I saw a related problem in another opened issue: #143

As soon as possible, I send a snippet of code here...

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

3 participants