[FIXED] Jetpack compose: No method shouldWaitForActivitiesToComplete()

Issue

I’m at the state where I want to write androidTests for the app.

Reading the docs of Testing Compose, I created a file and write a simple test to examine the progress:


ExamineTest.kt:

class ExamineTest {

    @get:Rule
    val composeTestRule = createComposeRule()


    @Test
    fun atLaunchDefaultTextExists() {
        composeTestRule.setContent {
            Text(text = "text")
        }
        composeTestRule.onNodeWithText("text").assertIsDisplayed()
    }
}

Also I added the debug AndroidManifest at the app/src/debug/ to enable ComposeActivity as suggested in docs.

However, by running the test nothing will happen and the test will not start executing.

Here’s the state that test gets stock at (App is built and deployed. But not started to run tests. Normal execution of app works correctly):

show case where test gets stuck

Am I missing a part on the setup ? What is the reason that tests are not running?


compose: 1.0.0-alpha05
AS: 4.2-canary 14

Update

After debugging the test and check it’s logs, I see this error:

No method shouldWaitForActivitiesToComplete() in 
androidx/test/runner/AndroidJUnitRunner 

Solution

Make sure test:monitor and test:core are up to date.

Checking out this issue on Android-test github, I realized the issue might be because of test:monitor being older than needed. So I did these steps:

  1. Check Gradle task app:dependencies to see the version of test:monitor library

  2. If it’s indeed old (which was 1.2.0 and not the latest 1.3.0), find the library that downgrades it.

    in my case fragment-testing was downgrading it to 1.2, so I removed it.

After making sure test:monitor and test:core are up to date, I could finally run the test

Answered By – Mahdi-Malv

Answer Checked By – Laura B. (Easybugfix Admin)

Leave a Reply

(*) Required, Your email will not be published