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.
}
}

Constructors

Link copied to clipboard
constructor(componentsConfiguration: ComponentsConfiguration? = null, themeResId: Int? = null, lithoVisibilityEventsController: () -> LithoVisibilityEventsController? = null)

Properties

Link copied to clipboard
Link copied to clipboard
val themeResId: Int? = null

Functions

Link copied to clipboard

Perform any interactions defined in the InteractionScope or on the LithoTestRule.

Link copied to clipboard
open override fun apply(base: Statement, description: Description): Statement
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 idle()

Runs through all tasks on the background thread and main lopper, blocking until it completes. Use if there are any async events triggered by layout ( ie visibility events) to manually drain the queue

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
fun setTreeProp(klass: Class<*>, instance: Any?): LithoTestRule

Sets a new TreeProp for the next layout pass.

Link copied to clipboard
Link copied to clipboard

Creates a ComponentTree that will propagate exceptions.