Thread
#multiplatform
    Hannes

    Hannes

    2 years ago
    Hey folks, I'm struggeling a bit with kotlin mutliplatform and
    commonTest
    . In my
    build.gradle
    i have the following config:
    kotlin {
      ... 
      sourceSets {
         ...
           commonTest {
                dependencies {
                    implementation 'org.jetbrains.kotlin:kotlin-test-common'
                    implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
                }
            }
       }
    }
    However, if I run a test in
    src/commonTest/kotlin/my/package/FooTest.kt
    which looks like this
    import kotlin.test.Test
    import kotlin.test.assertEquals
    
    class FooTest {
        @Test
        fun filterState(){
            assertEquals(1, 2)
        }
    }
    I get
    Unresolved reference: Test
    e: ... /src/commonTest/kotlin/my/package/FooTest.kt: (3, 20): Unresolved reference: Test
    e: ... /src/commonTest/kotlin/my/package/FooTest.kt: (4, 20): Unresolved reference: assertEquals
    Any idea what I have misconfigured?
    grandstaish

    grandstaish

    2 years ago
    I saw this once when my top level source folder for the common module was called
    java
    instead of
    kotlin
    Hannes

    Hannes

    2 years ago
    thanks, I double checked it, it's called
    kotlin
    Kris Wong

    Kris Wong

    2 years ago
    you need the test dependencies for your test targets as well
    if you are running a common test then it is probably defaulting to running using your JVM target, assuming you have one
    Hannes

    Hannes

    2 years ago
    What do you mean exactly? I only have
    commonMain
    , I just have a bunch of pure kotlin code in this library project that has no
    expected / actual
    platform specific implementation and therefore also no
    jvmTest
    etc.
    Kris Wong

    Kris Wong

    2 years ago
    you have to have a target
    otherwise what are you building?
    common source exists only to be shared with each of your targets
    Hannes

    Hannes

    2 years ago
    I have
    kotlin {
        jvm()
        js()
        macosX64()
        iosArm32()
        iosArm64()
        iosX64()
        ... 
        sourceSets {
         ...
           commonTest {
                dependencies {
                    implementation 'org.jetbrains.kotlin:kotlin-test-common'
                    implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
                }
            }
       }
    Kris Wong

    Kris Wong

    2 years ago
    right, so you have 6 targets. which one was used to run the tests?
    Hannes

    Hannes

    2 years ago
    Ah, now I see what you are pointing out (thanks a lot for taking the time and effort!) I just run
    gradlew check
    and it failed in
    compileTestKotlinJvm
    I guess I miss the dependencies in
    implementation 'org.jetbrains.kotlin:kotlin-test'
                    implementation 'org.jetbrains.kotlin:kotlin-test-junit'
    I had a different understanding how
    commonTest
    works
    Kris Wong

    Kris Wong

    2 years ago
    you will need the right dependencies for every target on which you want to run the tests
    that same principle applies for
    main
    dependencies as well
    Hannes

    Hannes

    2 years ago
    yea you are right (and I found that totally unintuitive)
    Kris Wong

    Kris Wong

    2 years ago
    just like in your own project, common sources are not the full implementation. and common dependencies are also not the full implementation.
    i mean it's possible, but i haven't seen any libraries where that's the case
    Hannes

    Hannes

    2 years ago
    Thanks a lot for your help!
    btw. is there a website / documentation that lists all the dependencies for each target? i.e. how do I find the kotlin test artifact for javascript?
    Kris Wong

    Kris Wong

    2 years ago
    the specific library should have it in their own docs. in this case, the new project template would also include it if it also generated the target.