Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

espresso-support Download License

This library includes components which facilitate testing Views in isolation and running Espresso tests with Google TalkBack enabled.

  • it allows you to inflate layouts/instantiate Views in their own Activity
  • adds automatic toggling of TalkBack before/after each test to assert custom behavior


The library is split into two artifacts, available on JCenter.

  • core includes most of this library's classes and functions. It should be included as an androidTestCompile dependency, since you'll only use it for instrumentation tests.
  • extras include two Activity components that are used by core. It's not enough to use androidTestCompile for this because that will include it as part of the test APK that instruments your app; they must be part of the app under test. Use debugCompile or <yourEspressoFlavor>Compile to include this dependency.
androidTestCompile 'com.novoda:espresso-support:<latest-version>'
debugCompile 'com.novoda:espresso-support-extras:<latest-version>'

See demo/build.gradle for examples.

Testing views in isolation

Use the ViewTestRule, passing in a layout resource. It'll inflate the resource into the ViewActivity with MATCH_PARENT for both dimensions. You can use rule.getView() to obtain an instance of the View and it'll be typed to the class you specified.

public ViewTestRule<MovieItemView> rule = new ViewTestRule<>(R.layout.test_movie_item_view);

You can write BDD style tests here, highlighting the expected behavior for your custom views, using a mixture of Espresso ViewActions and Mockito verifies:

public void givenViewIsUpdatedWithDifferentMovie_whenClicking_thenListenerDoesNotGetFiredForOriginalMovie() {


    verify(movieItemListener, never()).onClickPlay(eq(EDWARD_SCISSORHANDS));

private void givenMovieItemViewIsBoundTo(final Movie movie) {
    viewTestRule.runOnUiThread(new ViewTestRule.Runner<MovieItemView>() {
        public void run(MovieItemView view) {

Testing behavior with TalkBack enabled

Often, our apps will behave differently when TalkBack is enabled to offer a more streamlined experience for users of screen readers.

Use either TalkBackTestRule wrapped around a ViewTestRule/ActivityTestRule to start/stop TalkBack before and after each test.

private ViewTestRule<MovieItemView> viewTestRule = new ViewTestRule<>(R.layout.test_movie_item_view);

public RuleChain chain = RuleChain.outerRule(new TalkBackTestRule()).around(viewTestRule);

TalkBack will be enabled before each test is run and disabled after each test finishes.

⚠️ Toggling TalkBack state requires the WRITE_SECURE_SETTINGS permission being set for the app under test.


You can run the demo tests with the following command:

./gradlew demo:installDebug;\
adb shell pm grant com.novoda.movies android.permission.WRITE_SECURE_SETTINGS;\
adb shell am start -a com.novoda.espresso.DISABLE_ALL_SERVICES;\
./gradlew demo:cAT;
  1. First the app is installed
  2. The WRITE_SECURE_SETTINGS permission is set for the app (com.novoda.movies - replace this with your app's package name)
  3. Disable all accessibility services initially
  4. Run all the connected Android tests


Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, here is how
  • If you have a problem check the Issues Page first to see if we are working on it


Includes custom rules for testing Views in isolation and running tests with Google TalkBack enabled.




No packages published