Thread
#multiplatform
    jean

    jean

    1 year ago
    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
    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?
    andylamax

    andylamax

    1 year ago
    Don't use Dispatchers.Main in tests
    jean

    jean

    1 year ago
    Thanks 🙂 Using
    Dispatchers.Default
    instead seems to work
    Osman Saral

    Osman Saral

    1 year ago
    came here to ask same question 😄 i'm lucky i guess
    andylamax

    andylamax

    1 year ago
    yo welcome
    l

    leandro

    1 year ago
    you need to use the multithreaded version of coroutines, e.g.
    1.5.1-native-mt