Skip to content

Instantly share code, notes, and snippets.

@drawers
Last active January 25, 2021 01:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drawers/5bec0116dfb7bf79bb7e28396c9364f5 to your computer and use it in GitHub Desktop.
Save drawers/5bec0116dfb7bf79bb7e28396c9364f5 to your computer and use it in GitHub Desktop.
DDDTest.kt
class TasksViewModel: ViewModel {
val taskItems: LiveData<List<TaskItem>>
val _tasksItems: MutableLiveData<List<TaskItem>>
fun loadTasks() {
val tasks = tasksRepository.getAllTasks()
_taskItems.value = tasks.map { it.toTaskItem() }
}
}
class TasksViewModelTest {
@Test
fun `completedTasksAreRed`() {
viewModel.loadTasks()
val firstTask = tasksItemsLiveData.currentItems().first()
firstTask.isComplete.shouldBeTrue()
firstTask.color.shouldEqual(R.color.red)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment