Hi, I’m trying to test the size of Composable. I s...
# compose
j
Hi, I’m trying to test the size of Composable. I set the Assertions and
Modifier.size
to the same size, but the assertion fails. Am I using the aasertion api wrong?
Copy code
@Test
fun size_is_500_x_500() {
    val size = 500.dp
    testRule.setContent {
        Box(
            modifier = Modifier.size(
                size = size,
            ),
        )
    }
    testRule
        .onRoot()
        .assertWidthIsEqualTo(
            expectedWidth = size,
        )
        .assertHeightIsEqualTo(
            expectedHeight = size,
        )
}
Copy code
java.lang.AssertionError: Actual width is 392.72726.dp, expected 500.0.dp (tolerance: 0.5.dp)
z
You're might testing it on compact size device or emulator and devic has only 392.72.. width and this may be the reason of exception if you change orientation to landscape you will get same exception with height.
j
As you said, the device size was a problem. I reduced the size to 100 in my test code and it worked. thank you!