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

Fix Intents init/release in UI tests #79

Open
Jharaxus opened this issue Apr 16, 2023 · 0 comments
Open

Fix Intents init/release in UI tests #79

Jharaxus opened this issue Apr 16, 2023 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers refactoring Moves or deletes files in the project

Comments

@Jharaxus
Copy link
Contributor

As of now, initialization and release of intents are done at the beginning and the end of each Android UI test. Therefore, sometimes when a tests fails it doesn't release its intents (as it is supposed to happen after the assertions), which non-deterministically crashes other tests that then look like they double initialize their intents.

Example of such code:

    @Test
    fun validateProfileButtonGoToTheProfilePage() {

        Intents.init() // here

        // An intent with a name is sent to the activity
        val testIntent =
            Intent(ApplicationProvider.getApplicationContext(), ProfileModifyingActivity::class.java)
        testIntent.putExtra("userId", 1)
        ActivityScenario.launch<ProfileModifyingActivity>(testIntent)

        // Clicking on button
        button.performClick()
        Intents.intended(IntentMatchers.hasComponent(ProfileActivity::class.java.name))

        Intents.release() // here

    }

To fix this, one way could be to use the @Before and @After annotations to initialize and release the intents, therefore avoiding code duplication and enforcing that the release is always done.

@Jharaxus Jharaxus added bug Something isn't working good first issue Good for newcomers refactoring Moves or deletes files in the project labels Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers refactoring Moves or deletes files in the project
Projects
None yet
Development

No branches or pull requests

1 participant