Hello! I’m working on a Kotlin Multiplatform proje...
# community-support
g
Hello! I’m working on a Kotlin Multiplatform project that contains a
moduleA
and
moduleB
. Each module
commonMain
has a DI class with an
expect
function to provide their Koin setup. I’m currently writing tests for each module, so each
commonTest
also has its own DI class for setup. For example,
moduleA
uses SQLDelight, which requires a “testing driver” for tests. The issue arises because
moduleB
depends on
moduleA
and includes a repository that interacts with `moduleA`’s database. Unfortunately, I can’t import (resolve) the DI class from `moduleA`’s
commonTest
in
moduleB
, even though I can access `moduleA`’s
commonMain
DI class. However, I can’t use the
commonMain
version because it doesn’t include the “testing driver.” I’ve tried adding
moduleA
as a dependency in `moduleB`’s
build.gradle
under the
commonTest
source set, but it still won’t resolve. moduleB’s commonTest test class:
Copy code
@BeforeTest
    fun setUp() {
        startKoin {
            modules(       
                moduleADiModule() <<<< can resolve (from module A commonMain)
                moduleATestDiModule() <<<< cannot resolve (from module A commonTest)
            )
        }
    }
What am I missing? 🤔
j
In which source set are you adding the A test DI module?
If you are adding it to a commonTest source set, they are not shared between modules, so you need to add it to a commonMain in another module and add it as dependency on your test source sets A and B
g
The function
moduleADiModule()
belongs to
DI.kt
from
moduleA
commonMain. The function
moduleATestDiModule()
belongs to
DITest.kt
from
moduleA
commonTest.
moduleB
build.gradle:
Copy code
commonMain.dependencies {
    implementation(projects.moduleA)
...
}
commonTest.dependencies {
    implementation(libs.test.kotlin)
    implementation(libs.test.kmp.koin)
    implementation(libs.test.kmp.turbine)
    implementation(libs.test.kotlinx.coroutines)
}
j
You cannot share commonTest source sets as I said before.
g
ok so I need a “proxy” module in between with that logic in its commonMain so that module A and B can use it as a dependency on their commonMain/Test is that correct?
j
Correct 👍
Text fixtures are not supported by KMP, so you can only do that
g
okok, thanks 🙂
🙂 1
well in this case, it was easier to replicate the DI setup from commonTest in commonMain, to avoid some circular dependencies. 😅 anyway, I’ll keep an eye on https://youtrack.jetbrains.com/issue/KT-63142/Add-support-for-Gradle-Test-Fixtures-in-non-JVM-platforms 😊