I'm trying to remove the `withContext` from my vi...
# mockk
j
I'm trying to remove the
withContext
from my viewModel and I'm planning to put it on the
usecase
/
repository
something like this
Copy code
launch{
 updateView()
 withContext(<http://Dispatchers.IO|Dispatchers.IO>){
   doLogin(username,password)
 }
 updateView()
}
This is how I'm doing it now ^ Then if I want to remove the
withContext(<http://Dispatchers.IO|Dispatchers.IO>)
I can do it like this
Copy code
suspend fun doLogin(usernarme: String, password: String) = <http://Dispatchers.IO|Dispatchers.IO> { repo.doLogin(username,password)... }
So, is there any way to test it correctly? I'm using
mockK
so, I know with
coEvery
is going to work, but is it safe to do not put
Dispatchers.Uncofined
for testing purposes? Also do you think it's a good idea to do not change context on viewModel and then just do this
Copy code
launch {
 updateView()
 doLogin(username,password)
 updateView()
}
s
Try to avoid cross posting, since replies will get lost or scattered. Here's my reply in the other channel. https://kotlinlang.slack.com/archives/C1CFAFJSK/p1583238916133600?thread_ts=1583230365.129600&amp;cid=C1CFAFJSK
j
Just thought that someone from #mockk could help me if he/she's not on #coroutines channel, sorry 😄
s
You can share your message on another channel (but don’t over-use that either 🙂 )
👌 1