Test Kit for foldable devices

The Test Kit contains utility functions that help you write instrumented UI tests for foldable devices.

There are two library versions in the Test Kit:

The Compose version builds on the view system version and provides Compose wrappers for the utility functions.

Important

You will only need to import one library version in any project. If you only use traditional views, import the testing-kotlin version. Otherwise, if you use only composables, or a combination of composables and views, import the testing-compose version.

Add dependency

  1. Make sure you have the mavenCentral() repository in your top level build.gradle file:

    allprojects {
        repositories {
            google()
            mavenCentral()
         }
    }
    
  2. Add the dependency you need to the module-level build.gradle file (current version may be different from what's shown here):

    androidTestImplementation "com.microsoft.dualscreen.testing:testing-kotlin:1.0.0-alpha4"
    

Understand foldable concepts

When working with foldable devices, there are a few terms and concepts that are helpful to understand. See Foldable concepts for UI tests.

Write UI tests for foldables

When writing UI tests, there are a few ways to test app behavior on foldable devices.

Simulate folding features

Using the Jetpack Window Manager testing artifact, you can simulate a folding feature on any device/emulator to test how your layouts react. See Simulate folding features.

Simulate swipe gestures

Using UiAutomator and specific device dimensions, you can simulate spanning and unspanning gestures on the Surface Duo to test how your layouts react. See Simulate swipe gestures.

Test annotations

Using annotations, you can create tests for single-screen mode, dual-screen mode, device orientation, and folding features. See Test Kit annotations.