'how to Unit testing ViewModel listing Kotlin Coroutines?

i know this is something explained many times everywhere but i cannot find an answer for my current situation, maybe there is someone out there willing to help, a hint, an example.

I would love to test my ViewModel that gets a List of movies, feeding a RecyclerView, here it is my code, i would love to know how to start, i dont really understand it.

class TvShowViewModel
@Inject
constructor(private val repository: TvShowRepository) : ViewModel() {

    private val _response = MutableLiveData<List<TvShowItem>>()

    val responseTvShow: LiveData<List<TvShowItem>>
        get() = _response


    init {
       getAllTvShows()

    }


    fun getAllTvShows() = viewModelScope.launch {
        repository.getTvShows().let {response ->

            if (response.isSuccessful){
                _response.postValue(response.body())
            }else{
                Log.d("tag", "getAllTvShows Error: ${response.code()}")
            }
        }
    }
}

class TvShowRepository
@Inject
constructor(private val apiService: ApiService) {
    suspend fun getTvShows() = apiService.getTvShows()



}

interface ApiService {

   @GET(Constants.END_POINT)
   suspend fun getTvShows():Response<List<TvShowItem>>

}

Any help is really welcome, code examples, hints, anything please is really really welcome, i do not know how to start, there are many ways of doing this, and i am getting more and more confused because of that, the simplest way, or the most efficient are welcome, i just need to learn it, and see how to implement it.

Thanks a lot



Sources

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

Source: Stack Overflow

Solution Source