0

So I am trying to add a UI UnitTest in our app. And tried using the TestHarness from Accompanist to test our app in small and large screen device.

I provided the parameter size and in their documentation it would modify the LocalDensity and didn't mention if it would also modify the LocalConfiguration. But our app's use the screenWidthDp from LocalConfiguration to adjust which composable to display.

Hereis sample code test:

@Test
fun smallScreenTest() {
    composeTestRule.setContent {
        TestHarness(size = DpSize(width = 411.dp, height = 800.dp)) {
            MyScreen()
        }
    }

    composeTestRule.onNodeWithTag("BottomNavigation").assertExists()
}

@Test
fun largeScreenTest() {
    composeTestRule.setContent {
        TestHarness(size = DpSize(width = 1280.dp, height = 800.dp)) {
            MyScreen()
        }
    }

    composeTestRule.onNodeWithTag("DrawerNavigation").assertExists()
}

If the test smallScreenTest is run on tablet emulator it would fail and the largeScreenTest will also fail if run on phone emulator.

Anyone use the TestHarness and if this is how it works? Do I have to run each tests on different emulators?

SquareBox
  • 823
  • 1
  • 10
  • 22

0 Answers0