Espresso with Compose Empty Test Rule
This example highlights the use of the setEmptyComposeTestRule(params)
API available in axe DevTools Mobile with Compose. When utilizing the AxeDevToolsCompose
object in UITests with the ComposeEmptyTestRule
capabilities of Android, the setEmptyComposeTestRule(params)
aids in setting the library up properly.
Quick links:
- Setup for axe DevTools Mobile with Compose Layouts.
- API documentation for axe DevTools Mobile for Android.
- Read more on ComposeTestRule.
Below is an example of the AxeDevToolsCompose
object in an Espresso test when utilizing the ComposeEmptyTestRule
capabilities of Android.
Complete Example
@RunWith(AndroidJUnit4::class)
class EmptyComposeRuleAPITest {
@get:Rule
val composeEmptyTestRule = createEmptyComposeRule()
private lateinit var activity: ComponentActivity
lateinit var scenario: ActivityScenario<ComponentActivity>
companion object {
val axe = AxeDevToolsCompose()
init {
axe.connect(
"YOUR_API_KEY_HERE"
)
}
}
@Before
fun setup() {
scenario = ActivityScenario.launch(ComponentActivity::class.java)
scenario.onActivity { activity ->
this.activity = activity
activity.setContent {
Surface {
Column {
Text("Hello World")
}
}
}
}
composeEmptyTestRule.mainClock.autoAdvance = false
composeEmptyTestRule.waitForIdle()
}
@Test
fun doGenericScan() {
axe.setEmptyComposeTestRule(composeEmptyTestRule, activity)
axe.scan()?.uploadToDashboard()
}
}