# Testing Different Navigation Options with Compose

DevFeed: [Testing Different Navigation Options with Compose](<https://devfeed.tech/articles/testing-different-navigation-options-with-compose-38495.md>)

Original publisher: [Read original article](<https://eevis.codes/blog/2024-12-03/testing-different-navigation-options-with-compose/>)

Author: Eevis Panula

Published: 2024-12-04T03:34:51.328000Z

Content type: tutorial

Language: en

Sources: [Eevis Blog](<https://devfeed.tech/sources/eevis-blog.md>)

Topics: [Testing](<https://devfeed.tech/topics/testing.md>), [Compose](<https://devfeed.tech/topics/compose.md>), [Android](<https://devfeed.tech/topics/android.md>), [ui](<https://devfeed.tech/topics/ui.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [code](<https://devfeed.tech/tags/code.md>), [compose](<https://devfeed.tech/tags/compose.md>), [testing](<https://devfeed.tech/tags/testing.md>), [ui](<https://devfeed.tech/tags/ui.md>)

## AI overview

A tutorial showing how to write tests for alternative navigation methods in an accessible Android app built with Compose. It uses a graph demo project to demonstrate testing touch, keyboard, switch-device, and screen-reader navigation, including test setup and element selection with test tags.

## Source excerpt

One part of creating accessible Android apps is to provide alternative navigation options. Some examples include touch (or pointer) input, keyboard navigation, switch navigation, and screen reader navigation. But how can you write tests for these different ways of navigation? In this blog post, I'll share some examples of how to do that. I'm using an old demo project about making graphs more accessible and demonstrating how to write tests for the different elements I've explained with that demo project. About the Code We're Using As mentioned, I'm using an old demo project as the basis for the tests. In short, it contains a graph displaying data and is navigable with touch input, keyboard, switch device, and screen reader. The additional buttons for changing the highlighted sections in the chart also work for someone who has, for example, tremors in their hands or reduced dexterity. If you want to learn more about how I built the UI and the reasons behind the decisions, I've added links to all the blog posts in the Related Blog Posts section. Alright, let's get to writing tests! Setting Up The Tests Let's first set up the tests by creating a test class in the androidTest-package, defining composeTestRule, and adding a setup function that runs before each test: class GraphScreenTest { @get:Rule val composeTestRule = createComposeRule() @Before fun setupTests() { composeTestRule.setContent { GraphExampleTheme { GraphScreen() } } } } Another part of the setup phase is deciding how we will retrieve the elements we use for testing. In this case, I decided to use test tags for simplicity, and I've defined a TestTags-object for sharing between the UI and tests. This solution is straightforward and might not be your choice in a production app, but as this is a demo, it uses the most explicit option. You can find all the changes from this blog post in this commit. Touch Navigation The first tests we're going to write are about touch interaction. First, here's a short video o