LithoTestRule
class LithoTestRule @JvmOverloads constructor(val componentsConfiguration: ComponentsConfiguration? = null, val themeResId: Int? = null, lithoVisibilityEventsController: () -> LithoVisibilityEventsController? = null) : TestRule
This test utility allows clients to create a TestLithoView instance that allows to test assertion on the view hierarchy rendered by a Litho components.
@RunWith(AndroidJUnit4::class)
class LithoSampleTest {
@Rule @JvmField val LithoTestRule = LithoTestRule()
@Test
fun test() {
val testLithoView = LithoTestRule.render { TestComponent() }
// or you can use setRoot/measure/layout for more fine-grained control
val testLithoView = LithoTestRule.createTestLithoView().attachToWindow().setRoot(TestComponent()).measure().layout()
// Test your assertions on the TestLithoView instance.
}
}
Content copied to clipboard
Constructors
Link copied to clipboard
constructor(componentsConfiguration: ComponentsConfiguration? = null, themeResId: Int? = null, lithoVisibilityEventsController: () -> LithoVisibilityEventsController? = null)
Functions
Link copied to clipboard
fun act(testLithoView: TestLithoView, action: TestLithoView.InteractionsScope.() -> Unit): LithoTestRule
Perform any interactions defined in the InteractionScope or on the LithoTestRule.
Link copied to clipboard
fun createTestLithoView(lithoView: LithoView? = null, componentTree: ComponentTree? = null, widthPx: Int? = null, heightPx: Int? = null, widthSpec: Int = DEFAULT_WIDTH_SPEC, heightSpec: Int = DEFAULT_HEIGHT_SPEC, componentFunction: ComponentScope.() -> Component?? = null): TestLithoView
Creates new TestLithoView holder responsible for keeping an instance of LithoView, allowing to find Views/Components or perform assertions on it. For simple Component rendering without fine-grained control, use render
Link copied to clipboard
Link copied to clipboard
fun render(lithoView: LithoView? = null, componentTree: ComponentTree? = null, widthPx: Int? = null, heightPx: Int? = null, widthSpec: Int = DEFAULT_WIDTH_SPEC, heightSpec: Int = DEFAULT_HEIGHT_SPEC, componentFunction: ComponentScope.() -> Component?): TestLithoView
Sets the new root to render.
Link copied to clipboard
Sets a new TreeProp for the next layout pass.
Link copied to clipboard
Link copied to clipboard
Creates a ComponentTree that will propagate exceptions.