title: Coroutine Unit Testing Fails for the Class
body: <p>I am facing a weird issue while unit testing Coroutines. There are two tests on the class, when run individually, they both pass and when <em>I run the complete test class, one fails with assertion error</em>.
  I am using <code>MainCoroutineRule</code> to use the <code>TestCoroutineScope</code> and relying on the latest Coroutine Testing Library
  Here is the test :</p>
  
  <pre><code>    @Test
      fun testHomeIsLoadedWithShowsAndFavorites() {
          runBlocking {
              // Stubbing network and repository calls
              whenever(tvMazeApi.getCurrentSchedule("US", currentDate))
                  .thenReturn(getFakeEpisodeList())
              whenever(favoriteShowsRepository.allFavoriteShowIds())
                  .thenReturn(arrayListOf(1, 2))
          }
  
          mainCoroutineRule.runBlockingTest {
              // call home viewmodel
              homeViewModel.onScreenCreated()
              // Check if loader is shown
              assertThat(LiveDataTestUtil.getValue(homeViewModel.getHomeViewState())).isEqualTo(Loading)
              // Observe on home view state live data
              val homeViewState = LiveDataTestUtil.getValue(homeViewModel.getHomeViewState())
              // Check for success data
              assertThat(homeViewState is Success).isTrue()
              val homeViewData = (homeViewState as Success).homeViewData
              assertThat(homeViewData.episodes).isNotEmpty()
              // compare the response with fake list
              assertThat(homeViewData.episodes).hasSize(getFakeEpisodeList().size)
              // compare the data and also order
              assertThat(homeViewData.episodes).containsExactlyElementsIn(getFakeEpisodeViewDataList(true)).inOrder()
          }
      }
  </code></pre>
  
  <p>The other test is almost similar which tests for Shows without favorites. I am trying to test <code>HomeViewModel</code> method as:</p>
  
  <pre><code>        homeViewStateLiveData.value = Loading
          val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception -&gt;
              onError(exception)
          }
  
          viewModelScope.launch(coroutineExceptionHandler) {
              // Get shows from network and favorites from room db on background thread
              val favoriteShowsWithFavorites = withContext(Dispatchers.IO) {
                  val favoriteShowIds = favoriteShowsRepository.allFavoriteShowIds()
                  val episodes = tvMazeApi.getCurrentSchedule(COUNTRY_US, currentDate)
                  getShowsWithFavorites(episodes, favoriteShowIds)
              }
              // Return the combined result on main thread
              withContext(Dispatchers.Main) {
                  onSuccess(favoriteShowsWithFavorites)
              }
          }
      }
  </code></pre>
  
  <p>I cannot find the actual cause of why the tests if run separately are passing and when the complete class is tested, one of them is failing. Pls help if I am missing something</p>