[英]Is there a way to run instrumented Android tests under mutation with gradle and pitest?
我有一組在模擬設備上運行的檢測 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 配置突變測試,所以我不確定我是否遺漏了一些簡單的東西,或者這絕對不可能。
更新:根據 gradle-pitest-plugin 的維護者的說法,沒有 PITest 插件是不可能的。
如果您測試統一您的 UI 而不需要像他們說的那樣添加檢測機制:如果您在測試中使用替代的 Android 框架,如 Robolectric 或 UnMock Gradle 插件,您可能需要將 excludeMockableAndroidJar 添加到 pitest 配置excludeMockableAndroidJar = true
-> 對於 Robolectric
pitest {
targetClasses = ['com.myapp.*']
excludeMockableAndroidJar = true
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.