https://kotlinlang.org logo
Title
s

Saurabh Khare

02/18/2022, 7:57 AM
Hi, My testing need id for compose view, does anyone have idea how we can add id to compose view
s

Saurabh Khare

02/21/2022, 1:17 AM
@Colton Idle We are using testTag, but do you have idea how to generate unique number to testTag?
c

Colton Idle

02/21/2022, 7:19 AM
You would do it however you would do in java. There's nothing specific to compose in that.
m

mattinger

02/22/2022, 2:10 PM
@Saurabh Khare You wouldn't want to generate values for the test tag. You want them to be well known, so that you can access them inside your tests. I tend to create constants for my test tags:
const val MyButtonTag = "MyButton"

Button(modifier = Modifier.testTag(MyButtonTag)

composeTestRule.onNodeWithTag(MyButtonTag)