📸
AndroidUiTestingUtils
  • Overview
  • Setup
    • Instrumentation setup
    • Robolectric setup
    • Cross-Library setup
  • Usage
    • Instrumentation tests usage
      • Android-Testify usage
    • Robolectric usage
    • Cross-Library usage
    • TestRules & other utils
  • Ready-to-Run Samples
  • Github
Powered by GitBook
On this page
  • Application modules
  • System Locale
  • In-App Locale
  1. Setup

Instrumentation setup

PreviousSetupNextRobolectric setup

Last updated 8 months ago

Application modules

If you get any error due to "Activity not found" in your application module, add the following to the androidTest/manifest

<activity android:name="sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurator$PortraitSnapshotConfiguredActivity"/>
<activity android:name="sergio.sastre.uitesting.utils.activityscenario.ActivityScenarioConfigurator$LandscapeSnapshotConfiguredActivity"
    android:screenOrientation="landscape"/>

System Locale

To change the System Locale via SystemLocaleTestRule (i.e. necessary for snapshot testing Activities only), you also need to add the following permission to your androidTest/manifest. For multi-module apps, do this in the app module.

<!-- Required to change the System Locale via SystemLocaleTestRule (e.g. for snapshot testing Activities) -->
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"
    tools:ignore="ProtectedPermissions" />

And add the TestRule to your tests

@get:Rule
val systemLocale = SystemLocaleTestRule("en")

In-App Locale

AndroidUiTestingUtils also supports in instrumentation tests. In order to change the In-App Locale, you need to use the InAppLocaleTestRule. For that it is necessary to add the following dependency in your build.gradle

androidTestImplementation 'androidx.appcompat:appcompat:1.6.0-alpha04' // or higher version!

Use this rule to test Activities with in-app Locales that differ from the System Locale.

@get:Rule
val inAppLocale = InAppLocaleTestRule("en")
per-app language preferences