Skip to content

What is InstantTaskExecutorRule

Devrath edited this page Jul 7, 2021 · 3 revisions

Defining InstantTaskExecutorRule

  • This is a Junit rule used in test cases for tests that use android architecture components.
  • One such scenario is for the execution of livedata that happens instantly so that we can use the values in the test.

Gradle

testImplementation ‘android.arch.core:core-testing:1.1.1

Usage in code

@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()

More information

  • This rule swaps the background executor used by the architecture components with a different one that executes each task synchronously.
  • This is very important when writing the unit tests
  • Basically, it helps to execute tests one after another in a single thread all at once
Clone this wiki locally