'Unit Test viewModel using mockito and kotlin coroutine flow

I'm learning unit testing using Mockito, but I don't understand how to do this unit test on my viewModel, on this below the code of my viewModels,

    private val _state = MutableLiveData<Resource<ResponseMealsCategory>>()
    val states: LiveData<Resource<ResponseMealsCategory>> get() = _state

    fun loadAllCategories(){
        viewModelScope.launch {
            repository.getAllCategories()
                ?.onStart {
                    _state.postValue(Resource.onLoading(data = null))
                }
                ?.catch {
                    _state.postValue(Resource.onFailed(data = null, message = null))
                }
                ?.collect { category ->
                    _state.postValue(Resource.onSuccess(data = category))
                }
        }
    }
}

maybe someone can help me to do unit test on my viewModel?


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source