问题描述
我必须测试当前位置是否靠近某个特定位置。在我的测试课中,我试图通过设置经度和纬度来创建该特定位置,在应用程序中,这些数据来自后端。在我的测试课中,我手动输入它们。因为我的函数重复了太多次,所以我必须使用 junit5 提供的 ParametizedTest。但是使用 junit5 使我无法 RunWith(RoboElectricTestRunner.class)。相反,我开始使用 mannodermaus 插件通过 junit5 进行 Android 测试。它带来了另一个我无法弄清楚的问题,我的 Location 对象现在返回 null 而不是设置 lon 和 lat
private fun strings(): Stream<String?>? {
return Stream.of( "foo","bar")
}
@ParameterizedTest
@MethodSource("strings")
fun updateLocation(input: String) {
var lat = 12.494831
var lon = 83.49899
val startLocation = Location("start")
startLocation.latitude = lat
startLocation.longitude = lon
**println("startLocation = $startLocation") **//returns null****
}
在它工作正常之前,当我使用 JUnit4 和 @RunWith(RobolectricTestRunner.class) 时。现在我使用 junit5 和 mannodermaus 插件。
我的 build.gradle 文件如下所示。
apply plugin: 'de.mannodermaus.android-junit5'
apply from: rootProject.file('buildscripts/sonar.gradle')
android.buildFeatures.dataBinding = true
dependencies {
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$rootProject.kotlinVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion"
// External libraries
implementation "com.jakewharton.timber:timber:$rootProject.timberVersion"
// Android Architecture Components
api "androidx.lifecycle:lifecycle-extensions:$rootProject.lifecycLeversion"
api "androidx.lifecycle:lifecycle-common-java8:$rootProject.lifecycLeversion"
implementation 'joda-time:joda-time:2.10.5'
//testing libraries
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
testImplementation "org.junit.jupiter:junit-jupiter-params:5.7.0"
testCompile "org.robolectric:robolectric:4.3"
testImplementation "org.mockito:mockito-junit-jupiter:2.19.0"
androidTestImplementation "androidx.test.ext:junit:$rootProject.extjunitVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.espressoVersion"
}
android {
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
testOptions {
testOptions {
unitTests.returnDefaultValues = true
junitPlatform {
filters {
includeTags "slow"
excludeTags "integration"
}
debugFilters {
includeTags "integration"
}
}
}
}
kotlinoptions {
jvmTarget = "1.8"
}
//If your minSdkVersion is 24 or higher,then your issue will be resolved on its own,because VectorDrawables have full support starting with this API.
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)