[英]Is there a way to run instrumented Android tests under mutation with gradle and pitest?
I have a set of instrumented Android tests which run on an emulated device.我有一组在模拟设备上运行的检测 Android 测试。 I can run them with gradle using
gradlew connectedDebugAndroidTest
, and I've set up gradle-pitest-plugin like so:我可以使用
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
}
When I run gradlew pitest
or gradlew pitestDebug
, the emulator doesn't start, and only my unit tests run.当我运行
gradlew pitest
或gradlew pitestDebug
,模拟器没有启动,只有我的单元测试运行。 Specifying the instrumented test class in the pitest
config or specifying a different test runner doesn't help.在
pitest
配置中指定检测的测试类或指定不同的测试运行器无济于事。 I'm new to Android Studio and configuring mutation testing with gradle, so I'm not sure if I'm missing something simple or this absolutely isn't possible.我是 Android Studio 的新手并使用 gradle 配置突变测试,所以我不确定我是否遗漏了一些简单的东西,或者这绝对不可能。
更新:根据 gradle-pitest-plugin 的维护者的说法,没有 PITest 插件是不可能的。
If you are test unitary your UI without need the instrumented mecanisme add like they said : If you are using alternative Android framework in tests, like Robolectric or UnMock Gradle Plugin, you may want to add excludeMockableAndroidJar to pitest configuration excludeMockableAndroidJar = true
-> For Robolectric如果您测试统一您的 UI 而不需要像他们说的那样添加检测机制:如果您在测试中使用替代的 Android 框架,如 Robolectric 或 UnMock Gradle 插件,您可能需要将 excludeMockableAndroidJar 添加到 pitest 配置
excludeMockableAndroidJar = true
-> 对于 Robolectric
pitest {
targetClasses = ['com.myapp.*']
excludeMockableAndroidJar = true
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.