Challenge 1: A Fake Repository and ViewModel Unit Test — Solution class FakeTaskRepository : TaskRepository { private val _tasks = MutableStateFlow>(emptyList()) override val tasks: Flow> = _tasks.asStateFlow() override suspend fun addTask(task: Task) { _tasks.value = _tasks.value + task } } @Test fun `addTask adds the task to uiState`() = runTest { val fakeRepo = FakeTaskRepository() val viewModel = TaskViewModel(fakeRepo) viewModel.addTask("Buy milk") advanceUntilIdle() assertEquals(1, viewModel.uiState.value.tasks.size) assertEquals("Buy milk", viewModel.uiState.value.tasks.first().title) } Notes: - FakeTaskRepository implements the TaskRepository INTERFACE (Course 2, Chapter 8) with a simple in-memory MutableStateFlow instead of Room — this is only possible because TaskViewModel's constructor demands the interface, not a concrete Room-backed implementation. - runTest { } wraps the whole test body in a coroutine test scope; advanceUntilIdle() runs every pending coroutine (including viewModel.addTask's internal viewModelScope.launch, per Course 2 Chapter 6) to completion before the assertions run, so the test doesn't race against still-pending async work. - Because tasks is exposed via a StateFlow (built from a MutableStateFlow inside FakeTaskRepository), reading viewModel.uiState.value directly gives the CURRENT synchronous value — no separate collect{} needed just to check the test assertion.