A Rule is a way to run code before and after the execution of a test in JUnit.
Different kinds of rules
InstantTaskExecutorRule
is a JUnit rule that configuresLiveData
to execute each task synchronouslyMainCoroutineScopeRule
is a custom rule in this codebase that configuresDispatchers.Main
to use aTestCoroutineDispatcher
fromkotlinx-coroutines-test
. This allows tests to advance a virtual-clock for testing, and allows code to useDispatchers.Main
in unit tests. TheMainCoroutineScopeRule
lets you pause, resume, or control the execution of coroutines that are launched on theDispatchers.Main
.