Usage

In these sections, you'll find how to configure your screenshot tests with AndroidUiTestingUtils with different libraries. Currently, the following configurations are supported:

  • Locale

  • UI Mode (i.e. Light/Dark mode)

  • Custom theme

  • Font Size

  • Display Size

Font Size

Since SDK 34, Android uses non-linear font scaling and enabled users to scale system fonts up to 200%.

AndroidUiTestingUtils allows setting font scaling via FontSizeTestRule or fontSize configuration in the corresponding ActivityScenarioForXXXRule and RobolectricActivityScenarioForXXXRule, where XXX is an Activity, Fragment, View, Composable... You can set the font scaling factor value in several means:

Custom Font Scale

FontSizeScale.Value(1.25f)

Linear + Non-linear

You can also use the default values provided by AndroidUiTestingUtils, which correspond to those users can configure on their devices under Configuration > Accessibility > Font Size.

FontSize.SMALL               // 0.85f
FontSize.NORMAL              // 1.00f
FontSize.LARGE               // 1.15f
FontSize.XLARGE              // 1.30f
FontSize.XXLARGE             // 1.50f
FontSize.XXXLARGE            // 1.80f
FontSize.LARGEST             // SDK 34+ -> 2.00f, SDK < 34 -> 1.30f

FontSize.MAXIMUM_LINEAR      // 1.30f
FontSize.MAXIMUM_NON_LINEAR  // 2.00f

Keep in mind that the same value might result in a different screenshot depending on whether the SDK the tests are running on supports linear or non-linear font scaling

Some of these values are only available on devices running an SDK that supports non-linear scaling (i.e. SDK 34+)

You can get an Array with only the Linear/Non-Linear values depending on the SDK with FontSizeScale.supportedValuesForCurrentSdk()

You can find these values below

Linear

FontSize.SMALL        // 0.85f
FontSize.NORMAL       // 1.00f
FontSize.LARGE        // 1.15f
FontSize.LARGEST      // 1.30f

Previous to AndroidUiTestingUtils 2.3.0, only these values were supported

Non-linear

FontSize.SMALL      // 0.85f
FontSize.NORMAL     // 1.00f
FontSize.LARGE      // 1.15f
FontSize.XLARGE     // 1.30f
FontSize.XXLARGE    // 1.50f
FontSize.XXXLARGE   // 1.80f
FontSize.LARGEST    // 2.00f

FontSize.LARGEST applies different scale factors depending on the SDK.

Skip Tests

You can skip FontSizeScales that the current API Level does not support by using assumeSdkSupports at the beginning of the test, for instance:

private val targetFontSizeScale = FontSize.XXXLARGE

@get:Rule
val screenshotRule = ActivityScenarioForComposableRule(
        config = ComposableConfigItem(
            fontSize = targetFontSizeScale,
        )
    )

@Test
fun snapComposableTest() {
    // skips tests on SDK 34+, since XXXLARGE scale goes beyond 1.3f
    assumeSdkSupports(targetFontSizeScale)
    // your test here...
}

Last updated