我有一组在模拟设备上运行的经过测试的Android测试。我可以使用gradlew connectedDebugAndroidTest
使用gradle来运行它们,并且我已经像这样设置gradle-pitest-plugin:
buildscript {
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
}
configurations.maybeCreate('pitest')
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.ar.sceneform:plugin:1.13.0'
classpath 'pl.droidsonroids.gradle:gradle-pitest-plugin:0.2.2'
}
}
apply plugin: 'com.android.application'
apply plugin: 'pl.droidsonroids.pitest'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "my.application.id"
minSdkVersion 28
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'
}
debug {
testCoverageEnabled = true
}
}
useLibrary 'android.test.runner'
useLibrary 'android.test.base'
useLibrary 'android.test.mock'
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
dependencies {
// Provides ARCore Session and related resources.
implementation 'com.google.ar:core:1.13.0'
// Provides ArFragment, and other Sceneform UX resources:
implementation "com.google.ar.sceneform.ux:sceneform-ux:1.13.0"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
testImplementation "org.mockito:mockito-core:+"
// AndroidX Test dependencies
// Core library
androidTestImplementation 'androidx.test:core:1.0.0'
// AndroidJUnitRunner and JUnit Rules
androidTestImplementation 'androidx.test:runner:1.1.0'
androidTestImplementation 'androidx.test:rules:1.1.0'
// Assertions
androidTestImplementation 'androidx.test.ext:junit:1.0.0'
androidTestImplementation 'androidx.test.ext:truth:1.0.0'
androidTestImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-accessibility:3.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-web:3.1.0'
androidTestImplementation 'androidx.test.espresso.idling:idling-concurrent:3.1.0'
// The following Espresso dependency can be either "implementation"
// or "androidTestImplementation", depending on whether you want the
// dependency to appear on your APK's compile classpath or the test APK
// classpath.
androidTestImplementation 'androidx.test.espresso:espresso-idling-resource:3.1.0'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation "org.mockito:mockito-android:+"
implementation 'org.pitest:pitest:1.4.5'
}
pitest {
targetClasses = ['class.to.test.*']
threads = 5
outputFormats = ['HTML']
verbose = true
}
当我运行gradlew pitest
或gradlew pitestDebug
时,仿真器无法启动,仅运行单元测试。在pitest
配置中指定检测的测试类或指定其他测试运行程序无济于事。我是Android Studio的新手,并且使用gradle配置了变异测试,所以我不确定是否缺少简单的东西,或者这绝对不可能。
答案 0 :(得分:0)
更新:没有PITest插件according to the maintainer of gradle-pitest-plugin,这是不可能的。
答案 1 :(得分:0)
如果您要测试统一的UI,而无需使用检测到的mecanisme,请按如下说明进行添加:如果您在测试中使用替代的Android框架(例如Robolectric或UnMock Gradle插件),则可能需要在排除配置中添加excludeMockableAndroidJar
excludeMockableAndroidJar = true
->对于Robolectric
pitest {
targetClasses = ['com.myapp.*']
excludeMockableAndroidJar = true
}