bsimmons
03/02/2021, 4:55 PMrunBlocking for unit tests in a MPP for native/ios? It looks like kotlinx-coroutines-core:1.4.1 doesn't include runBlocking for native.Javier
03/02/2021, 4:58 PMrunBlocking exists for all except JSJavier
03/02/2021, 4:59 PMJavier
03/02/2021, 4:59 PMCasey Brooks
03/02/2021, 5:00 PMcommonTest sourceset, because it’s not available on all platforms. But you can use it in iosTest, or actual/expect it manually to be used in commonTestbsimmons
03/02/2021, 5:03 PMactual in iosMain but I'm getting this weird compilation error when I use it there,bsimmons
03/02/2021, 5:10 PM1.4.1 is conflicting with Ktor which is using 1.4.2-native-mt. Does that mean I am forced to use the native-mt version?John O'Reilly
03/02/2021, 5:27 PMnative-mt version....there's several libraries now that depend on thatJavier
03/02/2021, 5:28 PMJavier
03/02/2021, 5:28 PMJohn O'Reilly
03/02/2021, 5:30 PMbsimmons
03/02/2021, 5:35 PMJohn O'Reilly
03/02/2021, 5:36 PMbsimmons
03/02/2021, 5:41 PMJohn O'Reilly
03/02/2021, 5:45 PMbsimmons
03/02/2021, 5:52 PMCLOVIS
03/02/2021, 6:21 PMbsimmons
03/02/2021, 6:27 PMCLOVIS
03/02/2021, 8:58 PMbsimmons
03/02/2021, 9:20 PMJoost Klitsie
03/03/2021, 12:31 PMJoost Klitsie
03/03/2021, 12:34 PMopen class CoroutineHelper @Inject constructor() {
open val mainScope: CoroutineScope by lazy { CoroutineScope(Dispatchers.Main) }
open val mainContext: CoroutineContext by lazy { Dispatchers.Main }
open val mainImmediateScope: CoroutineScope by lazy { CoroutineScope(Dispatchers.Main.immediate) }
open val ioScope: CoroutineScope by lazy { CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>) }
open val defaultScope: CoroutineScope by lazy { CoroutineScope(Dispatchers.Default) }
open val ioContext: CoroutineContext by lazy { <http://Dispatchers.IO|Dispatchers.IO> }
open val defaultContext: CoroutineContext by lazy { Dispatchers.Default }
open val unconfinedScope: CoroutineScope by lazy { CoroutineScope(Dispatchers.Unconfined) }
}Joost Klitsie
03/03/2021, 12:34 PMclass TestCoroutineHelper : CoroutineHelper() {
override val mainScope: CoroutineScope
get() = CoroutineScope(Dispatchers.Unconfined)
override val mainContext: CoroutineContext
get() = Dispatchers.Unconfined
override val ioContext: CoroutineContext
get() = Dispatchers.Unconfined
}Joost Klitsie
03/03/2021, 12:35 PMprivate val coroutineHelper = TestCoroutineHelper()
private lateinit var presenter: BatteryStatusPresenter
override fun setUp() {
super.setUp()
presenter = BatteryStatusPresenter(
view, coroutineHelper, soundPool, context, appHelper, intentFactory)
}bsimmons
03/03/2021, 1:21 PM@Test though? If you don't use runBlocking {} won't the test just immediately finish and not wait for the coroutine to finish first?Joost Klitsie
03/03/2021, 1:30 PMJoost Klitsie
03/03/2021, 1:31 PM@Test fun myTest() { someClass.callToSuspendFunction() } doesn't work of course, as you cannot directly call a suspend functionbsimmons
03/03/2021, 1:34 PMlaunch or something in your suspend fun?Joost Klitsie
03/03/2021, 1:34 PM@Test fun myTest() { runBlocking { someClass.callToSuspendFunction() } } with runblocking you can call the suspend funbsimmons
03/03/2021, 1:37 PMDispatchers.Unconfined?Joost Klitsie
03/03/2021, 1:38 PMbsimmons
03/03/2021, 1:41 PMJoost Klitsie
03/03/2021, 1:43 PMJoost Klitsie
03/03/2021, 1:43 PM