我已经创建了一个新的Android项目,并在Indrumen测试和单元测试中设置了Mockk:
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
Gradle Sync Fine。
如果我添加kotlintest并再次同步,一切都起作用:
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
//Testing framework
androidTestImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.0'
}
但是,如果我删除kotlintest,并且在添加kotlintest之前就离开gradle文件,那么我会得到错误:
Failed to resolve: io
这是我的最终Gradle文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 29
buildToolsVersion "29.0.1"
defaultConfig {
applicationId "com.example.testing"
minSdkVersion 15
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
//Mocking framework
androidTestImplementation "io.mockk:mockk:{1.9.3}"
testImplementation "io.mockk:mockk:{1.9.3}"
}
我尝试清洁项目并清洁Gradle。
任何想法为什么会发生这种情况?
谢谢
mockk
库的版本包含 {}
。
使用在变量或ext
块中的版本时,我们通常会使用它们:
testImplementation "io.mockk:mockk:${Version.mockkVersion}"
在您的情况下,使用固定值时,您不应使用牙套:
testImplementation "io.mockk:mockk:1.9.3"
它应该与此更改同步