public class ViewModelTest
Base class for ViewModel testing.
Sample test:
class SampleViewModelTest : ViewModelTest() {
val mockViewState: SampleViewState = mockk()
lateinit var viewModel: SampleViewModel
@Before
fun setUp() {
viewModel = spyk(SampleViewModel(mockViewState), recordPrivateCalls = true)
}
@Test
fun `when ... then ...`() {
// GIVEN
...
// WHEN
...
// THEN
...
}}
| Constructor and Description |
|---|
ViewModelTest()
Base class for ViewModel testing.
|
| Modifier and Type | Method and Description |
|---|---|
CoroutineScopeRule |
getCoroutineScopeRule()
Swap coroutine dispatcher with the one that is executed immediately.
It allows to work with the coroutines.
|
androidx.arch.core.executor.testing.InstantTaskExecutorRule |
getInstantTaskExecutorRule()
Swap background android executor with the one that executes task synchronously.
It allows to work with the live data.
|
io.github.plastix.rxschedulerrule.RxSchedulerRule |
getRxJavaRule()
Swap RxJava schedulers with the ones that are executed immediately.
It allows to work with the RxJava.
|
void |
setCoroutineScopeRule(CoroutineScopeRule p)
Swap coroutine dispatcher with the one that is executed immediately.
It allows to work with the coroutines.
|
void |
setRxJavaRule(io.github.plastix.rxschedulerrule.RxSchedulerRule p)
Swap RxJava schedulers with the ones that are executed immediately.
It allows to work with the RxJava.
|
public ViewModelTest()
Base class for ViewModel testing.
Sample test:
class SampleViewModelTest : ViewModelTest() {
val mockViewState: SampleViewState = mockk()
lateinit var viewModel: SampleViewModel
@Before
fun setUp() {
viewModel = spyk(SampleViewModel(mockViewState), recordPrivateCalls = true)
}
@Test
fun `when ... then ...`() {
// GIVEN
...
// WHEN
...
// THEN
...
}}
@NotNull public io.github.plastix.rxschedulerrule.RxSchedulerRule getRxJavaRule()
Swap RxJava schedulers with the ones that are executed immediately. It allows to work with the RxJava.
public void setRxJavaRule(@NotNull
io.github.plastix.rxschedulerrule.RxSchedulerRule p)
Swap RxJava schedulers with the ones that are executed immediately. It allows to work with the RxJava.
@NotNull public androidx.arch.core.executor.testing.InstantTaskExecutorRule getInstantTaskExecutorRule()
Swap background android executor with the one that executes task synchronously. It allows to work with the live data.
@NotNull public CoroutineScopeRule getCoroutineScopeRule()
Swap coroutine dispatcher with the one that is executed immediately. It allows to work with the coroutines.
public void setCoroutineScopeRule(@NotNull
CoroutineScopeRule p)
Swap coroutine dispatcher with the one that is executed immediately. It allows to work with the coroutines.