LithoTestRule

class LithoTestRule @JvmOverloads constructor(val componentsConfiguration: ComponentsConfiguration? = null, val themeResId: Int? = null, lithoVisibilityEventsController: () -> LithoVisibilityEventsController? = null, lifecycleOwner: () -> LifecycleOwner? = null, resizeMode: LithoTestRuleResizeMode = LithoTestRuleResizeMode.AUTO, val androidContext: Context? = null, val attachToRealWindow: Boolean = false) : 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, lifecycleOwner: () -> LifecycleOwner? = null, resizeMode: LithoTestRuleResizeMode = LithoTestRuleResizeMode.AUTO, androidContext: Context? = null, attachToRealWindow: Boolean = false)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val androidContext: Context? = null
Link copied to clipboard

Renders into a real Activity window instead of the synthetic one, so that framework behavior only reachable from a real window is exercised. See TestLithoView.attachToWindow.

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

Creates a LithoView configured for screenshot capture.

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()

Drains all pending work on both the Litho layout thread and the main looper, repeating until both are simultaneously idle (quiescence).

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.