I’m following what KaMPKit wrote in this stackover...
# multiplatform
j
I’m following what KaMPKit wrote in this stackoverflow thread to test my sqldelight queries https://stackoverflow.com/questions/65663436/how-to-write-unit-tests-for-sqldelight-on-kmm My test succeeds in android but I get
kotlin.IllegalStateException: There is no event loop. Use runBlocking { ... } to start one.
when running the same test for ios. this is my BaseTest class in
iosTest
Copy code
actual abstract class BaseTest {
    @OptIn(DelicateCoroutinesApi::class)
    actual fun <T> runTest(block: suspend CoroutineScope.() -> T) {
        var error: Throwable? = null
        GlobalScope.launch(Dispatchers.Main) {
            try {
                block()
            } catch (t: Throwable) {
                error = t
            } finally {
                CFRunLoopStop(CFRunLoopGetCurrent())
            }
        }
        CFRunLoopRun()
        error?.also { throw it }
    }
}
I just copied what they have. Any idea what I’m doing wrong?
a
Don't use Dispatchers.Main in tests
j
Thanks 🙂 Using
Dispatchers.Default
instead seems to work
o
came here to ask same question 😄 i'm lucky i guess
a
yo welcome
l
you need to use the multithreaded version of coroutines, e.g.
1.5.1-native-mt