Skip to content

Instantly share code, notes, and snippets.

@alexvanyo
Last active January 25, 2023 22:08
Show Gist options
  • Save alexvanyo/110abf35a8b39c78efc7ef599466207b to your computer and use it in GitHub Desktop.
Save alexvanyo/110abf35a8b39c78efc7ef599466207b to your computer and use it in GitHub Desktop.
A flaky test with behavior that depends on the density of the device
/* Copyright 2023 Google LLC.
SPDX-License-Identifier: Apache-2.0 */
@Ignore("Flaky test, don't do this!)
@Test
fun checkHeightOfColumn() {
lateinit var density: Density
lateinit var layoutCoordinates: LayoutCoordinates
composeTestRule.setContent {
density = LocalDensity.current
Column(
Modifier.onPlaced { layoutCoordinates = it }
) {
repeat(6) {
Spacer(Modifier.height(10.dp))
}
}
}
composeTestRule.waitForIdle()
assertEquals(with(density) { 60.dp.roundToPx() }, layoutCoordinates.size.height)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment