Мой корневой файл build.gradle
buildscript {
repositories {
google()
mavenCentral()
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jacoco:org.jacoco.core:0.8.0"
}
}
apply plugin: 'android-sdk-manager'
allprojects {
apply plugin: 'jacoco'
apply plugin: 'com.github.ben-manes.versions'
repositories {
google()
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
tasks.withType(JavaCompile) {
sourceCompatibility = JavaVersion.VERSION_1_10
targetCompatibility = JavaVersion.VERSION_1_10
// report all Java errors even if the IDE does not
configure(options) {
compilerArgs << '-Xlint:all' << '-Xlint:-options'
deprecation = true
encoding = 'UTF-8'
}
}
// print errors from test in the terminal
tasks.withType(Test) {
testLogging {
exceptionFormat 'full'
}
}
project.plugins.whenPluginAdded { plugin ->
if ("com.android.build.gradle.AppPlugin".equals(plugin.class.name)) {
println "Disable pre dexing for module ${project.name}"
project.android.dexOptions.preDexLibraries = false
} else if ("com.android.build.gradle.LibraryPlugin".equals(plugin.class.name)) {
println "Disable pre dexing for module ${project.name}"
project.android.dexOptions.preDexLibraries = false
}
}
}
файл app / build.gradle
apply plugin: 'com.android.application'
apply from: '../jacoco.gradle'
android {
compileSdkVersion COMPILE_SDK_VERSION as int
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
applicationId "..."
minSdkVersion MIN_SDK_VERSION as int
targetSdkVersion TARGET_SDK_VERSION as int
project.ext.set("archivesBaseName", "..." + versionName)
multiDexEnabled true
renderscriptTargetApi RENDERSCRIPT_TARGET_API as int
renderscriptSupportModeEnabled true
}
signingConfigs {
debugKey {
...
}
releaseKey {
...
}
}
buildTypes {
debug {
versionNameSuffix ''
debuggable true
minifyEnabled false
zipAlignEnabled true
signingConfig signingConfigs.debugKey
testCoverageEnabled true
}
staging {
versionNameSuffix ''
debuggable false
minifyEnabled true
zipAlignEnabled true
signingConfig signingConfigs.stagKey
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
matchingFallbacks = ['release']
}
release {
versionNameSuffix ''
debuggable false
minifyEnabled true
zipAlignEnabled true
signingConfig signingConfigs.releaseKey
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'LICENSE.txt'
}
testOptions {
animationsDisabled true
unitTests {
returnDefaultValues = true
includeAndroidResources = true
}
}
lintOptions {
lintConfig file('lint.xml')
abortOnError false
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
}
}
dexOptions {
javaMaxHeapSize "3g"
jumboMode = true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
// Espresso
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// Junit
testImplementation "junit:junit:${JUNIT_VERSION}"
//Mockito
testImplementation "org.mockito:mockito-core:2.22.0"
...
}
и файл jacoco.gradle
apply plugin: 'jacoco'
def buildDir = "$project.buildDir"
def taskName = "debug"
def testTaskName = "testDebugUnitTest"
jacoco {
toolVersion "0.7.7.201606060606"
}
task "${testTaskName}Coverage"(type: JacocoReport, dependsOn: ["${testTaskName}", "createDebugCoverageReport"]) {
group = "Reporting"
description = "Generate Jacoco coverage reports on the ${testTaskName} build."
reports {
xml.enabled = true
html.enabled = true
html.destination file("$buildDir/jacoco")
csv.enabled false
}
def coverageSourceDirs = ["src/main/java"]
def fileFilter = [
'**/R.class',
'**/R$*.class',
'**/*$ViewInjector*.*',
'**/*$ViewBinder*.*',
'**/BuildConfig.*',
'**/Manifest*.*',
'android/**',
'com/google/**',
'com/intellij/**',
'junit/**',
'net/**',
'okhttp/**',
'org/**',
'rx/**',
'**/*_MembersInjector.class',
'**/Dagger*Component.class', // covers component implementations
'**/Dagger*Component$Builder.class', // covers component builders
'**/*Module_*Factory.class'
]
def javaClasses = fileTree(
dir: "$buildDir/intermediates/app_classes/${taskName}",
excludes: fileFilter
)
classDirectories = files([javaClasses])
sourceDirectories = files([coverageSourceDirs])
additionalSourceDirs = files([coverageSourceDirs])
executionData = fileTree(dir: "$buildDir", includes: [
"jacoco/testDebugUnitTest.exec"
])
}
и явыполнение следующей команды на mac
./gradlew clean testDebugUnitTestCoverage
Когда я запускаю эту команду, она показывает сообщение
Task ':app:testDebugUnitTestCoverage' is not up-to-date because:
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/index.html has been removed.
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/jacoco-sessions.html has been removed.
Output property 'reports.enabledDirectoryReportDestinations.html' file .../app/build/jacoco/jacoco-resources has been removed.
[ant:jacocoReport] Loading execution data file .../app/build/jacoco/testDebugUnitTest.exec
[ant:jacocoReport] Writing bundle 'app' with 3040 classes
, и в папке
reports/coverage/debug
* 1019 не вычисляется покрытие*
однако папка
tests/testDebugUnitTest
показывает данные успешно пройденных модульных тестов.