android-test
android-test copied to clipboard
`DisplaySizeRule` does not consistently set back the previous emulator state
Actual
The emulator remains with the display size modified. Wiping the device is required to restore the original state.
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.
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.