[英]Error Running Unit Tests for Kotlin Multiplatform Project
我按照本網站的教程使用 Intelli-j IDE(社區版)創建了一個 Kotlin 多平台項目:
我沒有遵循的是教程的 xCode 部分,因為此時雖然我希望這個項目是多平台的,但我的主要興趣是針對 Android。
當我運行common
示例測試時,我看到錯誤: e: org.jetbrains.kotlin.konan.MissingXcodeException: An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed.
e: org.jetbrains.kotlin.konan.MissingXcodeException: An error occurred during an xcrun execution. Make sure that Xcode and its command line tools are properly installed.
我還可以看到,對於關聯的配置,任務詳細說明如下: cleanIosTest iosTest
這就是我收到錯誤的原因。
我無法弄清楚的是如何更改Sample Test
以不運行該配置。 我試圖刪除這些任務,應用和保存,但是當我運行它們時它們不斷重新出現。 我在 build.gradle 文件中看不到任何表示 iOS 特定用於測試的內容。
構建.gradle.app
plugins {
id 'org.jetbrains.kotlin.multiplatform' version '1.3.72'
}
repositories {
google()
jcenter()
mavenCentral()
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId 'org.jetbrains.kotlin.mpp_app_android'
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName '1.0'
testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
}
kotlin {
android("android")
// This is for iPhone emulator
// Switch here to iosArm64 (or iosArm32) to build library for iPhone device
iosX64("ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain {
dependencies {
implementation kotlin('stdlib')
}
}
androidTest {
dependencies {
implementation kotlin('test')
implementation kotlin('test-junit')
}
}
iosMain {
}
iosTest {
}
}
}
// This task attaches native framework built from ios module to Xcode project
// (see iosApp directory). Don't run this task directly,
// Xcode runs this task itself during its build process.
// Before opening the project from iosApp directory in Xcode,
// make sure all Gradle infrastructure exists (gradle.wrapper, gradlew).
task copyFramework {
def buildType = project.findProperty('kotlin.build.type') ?: 'DEBUG'
def target = project.findProperty('kotlin.target') ?: 'ios'
dependsOn kotlin.targets."$target".binaries.getFramework(buildType).linkTask
doLast {
def srcFile = kotlin.targets."$target".binaries.getFramework(buildType).outputFile
def targetDir = getProperty('configuration.build.dir')
copy {
from srcFile.parent
into targetDir
include 'app.framework/**'
include 'app.framework.dSYM'
}
}
}
示例測試如下所示:
package sample
import kotlin.test.Test
import kotlin.test.assertTrue
class SampleTests {
@Test
fun testMe() {
assertTrue(Sample().checkMe() > 0)
}
@Test
fun testProxy() {
assertTrue(Proxy().proxyHello().isNotEmpty())
}
}
配置如下所示:
有誰知道如何在不需要下載 xCode 的情況下解決這個問題? 我很樂意分享任何其他信息,但我不確定我應該為此分享什么。
順便說一句,我確實創建了另一個沒有該行的配置,但是,當我在第一次測試中按下綠色的 PLAY 按鈕時,它總是默認為帶有 iOS 任務的Sample Test
配置。
此問題是由 Kotlin 問題跟蹤器中已描述的錯誤引起的,請參見此處。 如果您想運行僅適用於 Android 的測試,您應該使用名為test<Debug | Release>UnitTest
Gradle 任務test<Debug | Release>UnitTest
test<Debug | Release>UnitTest
而不是allTests
,其中包括您案例中唯一的 iOS。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.