winter-junit4 / io.jentz.winter.junit4 / GraphLifecycleTestRule / <init>

<init>

GraphLifecycleTestRule(application: WinterApplication = Winter)

JUnit4 test rule that allows to hook into the io.jentz.winter.Graph lifecycle.

This registers itself as Winter plugin on application before executing a test and unregisters itself afterwards.

Sample where we replace a view model in a presentation graph with a test view model:

val testViewModel = TestViewModel<ViewState>()

@get:Rule
val winterTestRule = object : GraphLifecycleTestRule() {
  override fun initializingGraph(parentGraph: Graph?, builder: ComponentBuilder) {
    if (builder.qualifier == "presentation") {
      builder.apply {
        singleton<ViewModel<QuotesViewState>>(generics = true, override = true) {
          viewModel
        }
      }
    }
  }
}