Skip to main content

Getting Started

The Litho Testing API is presented through the LithoViewRule class, it enables the following:

  • Make assertions against the Component hierarchy.
  • Mark assertions against the View hierarchy.
  • Provides access to utility functions to interact with the View hierarchy (such as by clicking).

LithoViewRule uses the Junit 'TestRule', which provides a flexible mechanism to execute code before and after a test method. As a result, Litho is able to prepare the environment then clean it up after testing has taken place, so there's no need to be concerned about it.

For more information about the TestRules, refer to the official JUnit documentation.

Adding Dependencies​

In order to use the Litho Testing API, the litho-testing dependency needs to be added into the relevant BUCK file:

deps = [


In order to use the @Rule inside of a test class, it needs to be initialised:

@Rule @JvmField val lithoViewRule = LithoViewRule()

Then, within a test, render the component with the help of the LithoViewRule.render(Component) method and perform assertions or other actions on the LithoView returned by the render call:

val testLithoView = lithoViewRule.render { TestComponent() }

What next?​

The remaining pages in this section describe how to use assertions and how to interact with components.