You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was creating integration tests the other day and when I tried to test observe() in an OnlineRepository subclass of mine, I was having a lot of exceptions.
Here is a gist of my test:
@Test
funobserveCachedData_data() {
val foo =listOf(
FooModel(id =1)
)
insertFoo(foo)
val body =GetFooResponse("", listOf())
val result =Result.response(Response.success(body))
`when`(service.getFoo(null)).thenReturn(
Single.just(result).subscribeOn(Schedulers.io()) // Run on background thread as a DB save is triggered.
)
`when`(responseProcessor.process(result)).thenReturn(ResponseProcessor.ProcessedResult<GetFooResponse>(null, "", body))
repository.loadDataRequirements =FooRepository.GetRequirements(null)
repository.observe()
.subscribeOn(Schedulers.io())
.test()
.awaitDone(500, TimeUnit.MILLISECONDS)
.assertValue {
it.data!!.size ==1
}
}
Looking above, I was able to fix my test with the line: Single.just(result).subscribeOn(Schedulers.io()) // Run on background thread as a DB save is triggered. from my mock. I had to make sure that fetchFreshData() was called on a background thread. Why? Because in the OnlineRepository source code I notice that the thread that is subscribed on in fetchFreshData() determines what thread saveData() is called on.
This is not right. A subclass of OnlineRepository should always know what thread something is executed on.
The text was updated successfully, but these errors were encountered:
For this issue, I will be following the same patterns that Teller-iOS is using. The guarantee that certain functions of an OnlineRepository subclass are called by certain threads.
I was creating integration tests the other day and when I tried to test
observe()
in anOnlineRepository
subclass of mine, I was having a lot of exceptions.Here is a gist of my test:
Looking above, I was able to fix my test with the line:
Single.just(result).subscribeOn(Schedulers.io()) // Run on background thread as a DB save is triggered.
from my mock. I had to make sure that fetchFreshData() was called on a background thread. Why? Because in theOnlineRepository
source code I notice that the thread that is subscribed on infetchFreshData()
determines what threadsaveData()
is called on.This is not right. A subclass of
OnlineRepository
should always know what thread something is executed on.The text was updated successfully, but these errors were encountered: