CLOVIS
07/27/2019, 7:16 PMCLOVIS
07/27/2019, 7:16 PMCLOVIS
07/27/2019, 7:27 PMsuspend operator fun get...
ashwini
07/28/2019, 8:10 AMMainCoroutineRule
to use the TestCoroutineScope
and relying on the latest Coroutine Testing Library
Here is the test :
@ExperimentalCoroutinesApi
@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()
}
}
The other test is almost similar which tests for Shows without favorites. I am trying to test HomeViewModel
method as:
fun onScreenCreated() {
homeViewStateLiveData.value = Loading
val coroutineExceptionHandler = CoroutineExceptionHandler { _, exception ->
onError(exception)
}
viewModelScope.launch(coroutineExceptionHandler) {
// Get shows from network and favorites from room db on background thread
val favoriteShowsWithFavorites = withContext(<http://Dispatchers.IO|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)
}
}
}
I cannot find the actual cause of why the tests if run separatly are passing and when the complete class is tested, one of them is failing. Pls help if I am missing somethingdave08
07/28/2019, 2:48 PMCLOVIS
07/28/2019, 6:56 PMCLOVIS
07/28/2019, 7:08 PM// I want to request ID 12
val results = Channel<Int, Channel<Result>>()
cacheManager.send(12, results)
val result: Result = results.receive()
Maybe this is where Flows would be useful?CLOVIS
07/28/2019, 7:10 PMalexsullivan114
07/30/2019, 1:06 AMcoEvery
method on mockk to to mock out a suspending call.
The crash is caused by a ClassNotFoundException
for kotlinx.coroutines.experimental.BuildersKt
Has anyone run into this?alexsullivan114
07/30/2019, 1:07 AMcoEvery
is deprecated but I can't find any documentation that says that it's deprecated...alexsullivan114
07/30/2019, 1:14 AMmockk
library!myanmarking
07/30/2019, 1:43 PMmyanmarking
07/30/2019, 1:43 PMmyanmarking
07/30/2019, 1:44 PMmyanmarking
07/30/2019, 1:44 PMursus
07/31/2019, 2:58 PMursus
07/31/2019, 2:59 PMjw
07/31/2019, 3:01 PMExecutor
wrapped around the IO dispatcher.
Synchronous calls would be even worse since you entirely defeat HTTP/2's connection multiplexing.ursus
07/31/2019, 3:03 PMursus
07/31/2019, 3:03 PMjw
07/31/2019, 3:04 PMcreate()
and not createAsync()
when creating the adapterSoren Valle
07/31/2019, 3:04 PMjw
07/31/2019, 3:04 PMursus
07/31/2019, 3:05 PMcreate
, .. so is that still bad because of the multiplexing thing?groostav
08/01/2019, 7:31 PMpublic interface CoroutineScope {
public val coroutineContext: CoroutineContext
}
vs
public suspend inline val coroutineContext: CoroutineContext
Soren Valle
08/01/2019, 7:32 PMansman
08/02/2019, 1:08 PMreplay(1).refCount()
in RxJava)Aldo Wachyudi
08/03/2019, 2:49 AMamrelmasry
08/04/2019, 2:10 PMAbstractCoroutine.start
, Where can I go from there? maybe I should check the Kotlin compiler? any starting points?