新しいjacocoタスクで最小カバレッジを確認する必要があります
jacocoTestCoverageVerification
このタスクは、3.4.1gradleリリースおよびjacocoプラグイン> = 0.6.3で使用できます。
ブランチカバレッジを含むhtmlレポートを生成する別のタスクを実行することもできますが、その番号を使用してビルドを失敗させたいと思います。
これは私のコードです
buildscript {
ext {
....
}
repositories {
mavenCentral()
maven {
....
}
}
dependencies {
.....
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
jar {
baseName = "coverage-test"
}
dependencies {
// my dependencies
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
wrapper {
gradleVersion = '3.4.1'
}
jacoco {
toolVersion = '0.7.9'
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
}
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
additionalSourceDirs = files(sourceSets.main.allJava.srcDirs)
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(
dir: it,
excludes:
[
'com/jacoco/dto/**',
'com/jacoco/configs/**',
//and others
])
})
}
}
jacocoTestCoverageVerification {
//I tried this and it didn't work
// classDirectories = files(classDirectories.files.collect {
// fileTree(
// dir: it,
// excludes:
// [
// 'com/jacoco/dto/**',
// 'com/jacoco/configs/**',
// //and others
// ])
// })
violationRules {
rule {
//Also tried this and it didn't work
// excludes = ['com/jacoco/dto/**', ...]
limit {
counter = 'BRANCH'
minimum = 0.8
}
}
}
}
check.dependsOn jacocoTestCoverageVerification
classDirectories私は、次のようなエラーが取得ヌルオブジェクトのプロパティ「ファイル」を取得できません。また、2番目のオプション(除外のみ)を使用すると、ビルドはスムーズに実行されますが、クラスは除外されません。
あなたはあなたが除外している別のものを測定しています。デフォルトのJaCoCoスコープは「BUNDLE」です。これはコード全体を意味すると思います。私はそれを使ったことがありません。私は常に「CLASS」スコープのみを測定します。そして、あなたは同じことをしようとしているようです。
除外は、スコープ内の要素に関連しています。「BUNDLE」の意味はよくわかりませんが、全部かゼロかと思いがちです。また、除外は異なるタイプのワイルドカードを使用します。要素「CLASS」(または「PACKAGE」)を使用するように構成を変更してみてください。
violationRules {
rule {
element = 'CLASS'
excludes = ['com.jacoco.dto.*']
limit {
counter = 'BRANCH'
minimum = 0.8
}
}
}
check.dependsOn jacocoTestCoverageVerification
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加