android-test icon indicating copy to clipboard operation
android-test copied to clipboard

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

Open adavis opened this issue 1 year ago • 1 comments

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.

adavis avatar Jan 26 '25 19:01 adavis

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.

kmcauliffe6 avatar Feb 05 '25 19:02 kmcauliffe6