在Kotlin Multiplatform中,当只有commonTest时,Gradle是否应该在所有平台上运行测试?

移动开发 2026-07-10

I think I am missing something here.

我想我这里是不是遗漏了什么。

I cloned https://github.com/Kotlin/multiplatform-library-template for a new project and have done changes accordingly. The library structure in library src is commonMain, commonTest, jsMain jvmMain nativeMain, but when I do ./gradlew build it starts running tests for jvmTest, iosSimulatorArm64Test and jsBrowserTest but in my mind there is no need for gradle to do that. As a result gradle fails because there are no tests to run.

我为一个新项目克隆了 https://github.com/Kotlin/multiplatform-library-template,并据此进行了修改。库在library src的结构是 commonMaincommonTestjsMainjvmMainnativeMain,但当我执行 ./gradlew build 时,它开始对 jvmTestiosSimulatorArm64TestjsBrowserTest 进行测试,而在我看来,Gradle没有必要这样做。因此 gradle 失败,因为没有要运行的测试。

TL;DR Can anyone confirm that gradle be running tests on all platforms when there is only commonTest?

TL;DR能否确认当只有commonTest时,Gradle会在所有平台上运行测试吗?

解决方案

TL;DR yes, if you have commonTest it will run commonTest on all declared platforms.

TL;DR是的,如果你有 commonTest,它将对所有声明的平台运行 commonTest

I tried working with a fresh project created via gradle, copied only the Main code and built it no tests run. When I copy across commonTest it runs the test for all declared platforms:jvm -> jvmTest, js browser -> jsBrowserTest, js node -> jsNodeTest, iosSimulatorArm64 -> iosSimulatorArm64Test etc.

我尝试用通过Gradle创建的一个全新项目来工作,只复制了 Main 代码并进行构建,结果是 没有测试运行。当我复制 commonTest 时,它会对所有声明的平台运行测试:jvm -> jvmTestjs browser -> jsBrowserTestjs node -> jsNodeTestiosSimulatorArm64 -> iosSimulatorArm64Test 等等。

站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。

相关文章