Visitar URL original
`DisplaySizeRule` does not consistently set back the previous emulator state · Issue #2334 · android/android-test · GitHub
Skip to content

DisplaySizeRule does not consistently set back the previous emulator state #2334

Open

Description

@adavis

Actual

The emulator remains with the display size modified. Wiping the device is required to restore the original state.
Image

Full test code (if helpful)

@OptIn(ExperimentalTestApi::class)
@RunWith(AndroidJUnit4::class)
class AppNavigationTests {

    @get:Rule(order = 0)
    val koinRule = KoinTestRule(
        modules = listOf(
            module {
                singleOf(::FakeConferenceRepository) bind ConferenceRepository::class
                viewModelOf(::MainViewModel)
            }
        )
    )

    @get:Rule(order = 1)
    val composeRule = createAndroidComposeRule<ComponentActivity>()

    @get:Rule(order = 2)
    var displaySizeRule: DisplaySizeRule = DisplaySizeRule()

    @Test
    fun should_display_bottom_bar_when_compact() {
        onDevice().setDisplaySize(
            widthSizeClass = WidthSizeClass.COMPACT,
            heightSizeClass = HeightSizeClass.MEDIUM
        )

        composeRule.setContent {
            Red30TechApp()
        }

        composeRule
            .onNodeWithTag("ui:bottomBar").assertIsDisplayed()
    }

    @Test
    fun should_display_rail_when_medium() {
        onDevice().setDisplaySize(
            widthSizeClass = WidthSizeClass.MEDIUM,
            heightSizeClass = HeightSizeClass.MEDIUM
        )

        composeRule.setContent {
            Red30TechApp()
        }

        composeRule
            .onNodeWithTag("ui:navigationRail").assertIsDisplayed()
    }
}

Expected

The emulator is restored to its original state.

Activity

  1. paigemca commented on Feb 5, 2025

    @paigemca
    Collaborator

    Hi Annyce, thank you for filing this issue!

    Are the test cases in the sample you shared failing? I'm able to reproduce this issue of the emulator not being set back to it's original state when a test case fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions