kotlin互惠图do not do not die do

发布于 2025-02-10 23:30:17 字数 4223 浏览 1 评论 0原文

我正在为Kotlin Multiplatform(KMP)的iOS和Android Native方面的编写测试而苦苦挣扎。我在一个模块中创建了几个接口(称为共享),并创建了另一个模块,称为sharedTests,其中我创建了示例测试(firstTest.kt )。看看下面的图片。问题是,KMP没有从共享中看到任何文件,为什么?我希望能够从该目录中访问每个文件,您如何告诉KMP要查看哪些目录?另外,我不知道为什么我的测试注释错误,因为我已经增加了依赖性。

import kotlin.test.BeforeTest
import kotlin.test.Test

open class FirstTest(private var concreteApp: IAppWrapper) {

    private lateinit var app: IAppWrapper

    @BeforeTest
    fun setUpTests(){
        app = concreteApp
    }

    @Test
    fun testOne(){
        //testing...
    }

}

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android()

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdk = 32
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 32
    }
}
dependencies {
    implementation("androidx.test:monitor:1.5.0")
    implementation("junit:junit:4.13.2")
    testImplementation("junit:junit:4.13.2")
}

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android()
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "testModule"
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdk = 32
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 32
    }
}
dependencies {
    implementation ("org.jetbrains.kotlin:kotlin-test-annotations-common:1.7.0")
    implementation("org.testng:testng:6.9.6")
    implementation ("org.jetbrains.kotlin:kotlin-test-junit:1.7.0")
    implementation("androidx.test:monitor:1.5.0")
    implementation("junit:junit:4.13.2")
    testImplementation("junit:junit:4.13.2")

}

I am struggling with writing tests for both iOS and Android native side in Kotlin Multiplatform (KMP). I created a couple of interfaces in one module (it's called shared) and created another module, called sharedTests, where I created sample test (FirstTest.kt). Take a look at pictures below. The problem is, that KMP doesn't see any files from shared, why is that? I want to be able to access every file from that directory, how do you tell KMP which directories to look at? Also, I have no idea why are my Test annotations wrong, because I have already added dependencies.

enter image description here

enter image description here

import kotlin.test.BeforeTest
import kotlin.test.Test

open class FirstTest(private var concreteApp: IAppWrapper) {

    private lateinit var app: IAppWrapper

    @BeforeTest
    fun setUpTests(){
        app = concreteApp
    }

    @Test
    fun testOne(){
        //testing...
    }

}

shared Gradle file:

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android()

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "shared"
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdk = 32
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 32
    }
}
dependencies {
    implementation("androidx.test:monitor:1.5.0")
    implementation("junit:junit:4.13.2")
    testImplementation("junit:junit:4.13.2")
}

sharedTests Gradle file:

plugins {
    kotlin("multiplatform")
    id("com.android.library")
}

kotlin {
    android()
    
    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64()
    ).forEach {
        it.binaries.framework {
            baseName = "testModule"
        }
    }

    sourceSets {
        val commonMain by getting
        val commonTest by getting {
            dependencies {
                implementation(kotlin("test"))
            }
        }
        val androidMain by getting
        val androidTest by getting
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by creating {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val iosX64Test by getting
        val iosArm64Test by getting
        val iosSimulatorArm64Test by getting
        val iosTest by creating {
            dependsOn(commonTest)
            iosX64Test.dependsOn(this)
            iosArm64Test.dependsOn(this)
            iosSimulatorArm64Test.dependsOn(this)
        }
    }
}

android {
    compileSdk = 32
    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    defaultConfig {
        minSdk = 21
        targetSdk = 32
    }
}
dependencies {
    implementation ("org.jetbrains.kotlin:kotlin-test-annotations-common:1.7.0")
    implementation("org.testng:testng:6.9.6")
    implementation ("org.jetbrains.kotlin:kotlin-test-junit:1.7.0")
    implementation("androidx.test:monitor:1.5.0")
    implementation("junit:junit:4.13.2")
    testImplementation("junit:junit:4.13.2")

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文