Testing Composables in Android Jetpack Compose

Testing a UI created with Compose is different from testing a View-based UI. Testing Composable UIs to verify the correct behaviour of your Compose code and improving the app’s quality by catching errors early in the development process is quite crucial for a robust user experience. Compose provides a set of testing APIs to find elements, verify their attributes and perform user actions. In this course, explore how to set up the test environment, where to put the test classes and how to write & run test cases. You'll explore how we can access Composables within a test environment, perform operations on them and can validate the test results. For reference, we'll create a profile editing screen in which we'll write tests for different UI validations before saving the profile. At the end of this course, you'll be able to write and run tests for your Composables in Android. 

In this coffee break codelab, you'll explore:
  • Setting up environment and dependencies for UI tests 
  • Creating test classes with Android JUnit 
  • Writing test cases for different UI validations 
  • Adding Rules for accessing Composables within the test environment 
  • Identifying Composables with tags and text for testing 
  • Exploring different finders, assertion and action APIs for testing 
  • Using @Before and @After annotations for test case processing 
  • Differences between test and androidTest packages 
  • Understanding what to test & how to test 
  • Running the tests and verifying the results 

Meet the instructor

Saurabh Pant 

Content Author & Course Instructor

More courses by the instructor

\Learnworlds\Codeneurons\Pages\ZoneRenderers\CourseCards