kotlin互惠图do not do not die do
我正在为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.
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论