Hello everyone, I'm running into a problem when te...
# multiplatform
p
Hello everyone, I'm running into a problem when testing my code in
commonMain
. I can't use
kotlin.test.Test
. I followed https://kotlinlang.org/docs/gradle.html#set-dependencies-on-test-libraries, which resulted in the following `build.gradle.kts`:
Copy code
kotlin {
    android()
    jvm("desktop") {
        compilations.all {
            kotlinOptions.jvmTarget = "11"
        }
    }
    sourceSets {
        jvm {
            testRuns["test"].executionTask.configure {
                useJUnitPlatform()
            }
        }

...        

        val commonTest by getting {
            dependencies {
                implementation(kotlin("test-common"))
                implementation(kotlin("test-annotations-common"))
                implementation("io.kotest:kotest-assertions-core:${Versions.kotest}")
            }
        }
...
The project overall is pretty empty, as in there are only the basic build steps. I looked up some other example repositories and also refreshed the dependencies, but it seems that I have missed something. I would be more than happy if anyone has a heads up of what might be wrong. Thanks in advance!
r
I haven't tried the new single-test-dependency setup yet, but I think you're supposed to use
kotlin("test")
instead of
kotlin("test-common")
p
Thanks for the heads up, fixed it. Still, seems to be another issue: (Kotlin-test is also listed under external libraries, so not sure what the problem is)
j
kotlin-test is working perfectly for me with 1.5.0, before I was using test-multiplatform or something so
Well, I revisit my project and it is finding the sources, but the project doesnt compile, time to come back to multiplatform test I guess ­čśé
i
j
Unrelated problem, i fixed that problem and now it is working with kotlin-test
p
Okay I'm not sure where the error lies, but this is my scenario:
Copy code
val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
//                implementation(kotlin("test-common"))
//                implementation(kotlin("test-annotations-common"))
                implementation(project(":backend"))
                implementation("io.kotest:kotest-assertions-core:${Versions.kotest}")
            }
        }
If I import
test-common
and
test-annotations-common
I get the annotation, but can't run the test (I guess there is a missing gradle task?). If I use
kotlin("test")
I can't use the annotation (and ofc can't run the test therefore. The deps seem to be there, but don't even include the
@Test
annotation: I already reinstalled/refreshed my gradle dependencies a few times, didn't solve it. I could move from Kotlin 1.4.30 to 1.5 like @Javier proposed, but I was a little bit shy of that until now.
j
try the multiplatform one
I don't remember if it is kotlin("test-multiplatform") or kotlin("multiplatform-test")
another thing is I have to import the test annotation manually some times
I think it was kotlin.test.Test
p
implementation(kotlin("test-multiplatform"))
it is! Thanks for your patience, it finally runs.
j
Remember replace it with test when you upgrade to 1.5.0
p
Oh yes, that's an important point. First I have to find out what things I have to add to the build to make it work with the IR compiler.
j
you have to just change the version I think, you can have problems with 3 party libraries
for example Koin is having problems with the duration API change