I’m getting NPE when trying to build macrobenchmar...
# compose
a
I’m getting NPE when trying to build macrobenchmarks with jetpack compose.
Copy code
java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.test.uiautomator.UiObject2.setGestureMargin(int)' on a null object reference
Here is my ScrollBenchmark:
Copy code
@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:
Copy code
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")
                        }
                    }
                })
 
            }
        }
    }
}
Why can’t it find the LazyColum tagged with “mylist” ? I did everything explained in the Macrobenchmark codelab: https://developer.android.com/codelabs/android-macrobenchmark-inspect#0
I forgot to add
Copy code
Modifier.semantics {
    // Allows to use testTag() for UiAutomator resource-id.
    testTagsAsResourceId = true
}
high up in the hierarchy. Now its working
132 Views