Aaron Waller
09/02/2022, 5:44 PMjava.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.test.uiautomator.UiObject2.setGestureMargin(int)' on a null object reference
Aaron Waller
09/02/2022, 5:45 PM@RunWith(AndroidJUnit4::class)
class ScrollBenchmarks {
@get:Rule
val benchmarkRule = MacrobenchmarkRule()
@Test
fun scroll() {
benchmarkRule.measureRepeated(
packageName = "com.example.composespeedtest",
iterations = 5,
metrics = listOf(FrameTimingMetric()),
startupMode = StartupMode.COLD,
setupBlock = {
pressHome()
startActivityAndWait()
}
) {
val contentList = device.findObject(By.res("mylist"))
contentList.setGestureMargin(device.displayWidth / 5)
contentList.fling(Direction.DOWN)
device.waitForIdle()
}
}
}
And here my modifier Tag:
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ComposeSpeedTestTheme {
LazyColumn(modifier = Modifier.testTag("mylist"),content = {
items(100) { i ->
Button(onClick = { /*TODO*/ }) {
Text(text = "$i")
}
}
})
}
}
}
}
Aaron Waller
09/02/2022, 5:47 PMAaron Waller
09/02/2022, 6:08 PMModifier.semantics {
// Allows to use testTag() for UiAutomator resource-id.
testTagsAsResourceId = true
}
high up in the hierarchy.
Now its working