`DisplaySizeRule` does not consistently set back the previous emulator state

Open
#2,334 1 comment 0 reactions 1 assignee View on GitHub

@paigemca is already working on this.

Since Jan 27, 2025.

Assessment

This issue has not been assessed yet.

Description

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.

Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
1d 14h
Merged PRs (30d)
5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from android/android-test

All issues in android/android-test

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.