Skip to content

Commit 4818133

Browse files
author
Pablo
committed
jacoco full report
1 parent 5ddf179 commit 4818133

File tree

3 files changed

+60
-12
lines changed

3 files changed

+60
-12
lines changed

.github/workflows/pr-build.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: PR Build
2+
on: [pull_request]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: Checkout
8+
uses: actions/[email protected]
9+
10+
- name: Set up JDK environment
11+
uses: actions/setup-java@v3
12+
with:
13+
java-version: 1.8
14+
15+
- name: Build all artifacts
16+
id: buildAllApks
17+
uses: gradle/gradle-build-action@v2
18+
with:
19+
gradle-version: current
20+
wrapper-cache-enabled: true
21+
dependencies-cache-enabled: true
22+
configuration-cache-enabled: true
23+
arguments: assembleDebug jacocoFullReport

jacoco.gradle

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def androidExclusion = [
1+
def reportExclusion = [
22
'**/databinding/**/*.*',
33
'**/android/databinding/*Binding.*',
44
'**/BR.*',
@@ -10,14 +10,20 @@ def androidExclusion = [
1010
'**/Dagger*Component.*',
1111
'**/Dagger*Component$Builder.*',
1212
'**/*Module_*Factory.*',
13-
'**/*Fragment*.*',
14-
'**/*Activity*.*',
15-
'**/*Adapter*.*',
16-
'**/*ViewPager*.*',
17-
'**/*ViewHolder*.*',
1813
'**/*Module*.*'
1914
]
2015

16+
def validationExclusion = [
17+
'*Fragment*',
18+
'*Activity*',
19+
'*Adapter*',
20+
'*ViewPager*',
21+
'*View*',
22+
'*ViewGroup*',
23+
'*Layout*',
24+
'*ViewHolder*',
25+
]
26+
2127
task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
2228

2329
group = "Reporting"
@@ -30,11 +36,11 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
3036

3137
def javaBuildTree = fileTree(
3238
dir: "build/intermediates/javac/debug/",
33-
excludes: androidExclusion
39+
excludes: reportExclusion
3440
)
3541
def kotlinBuildTree = fileTree(
3642
dir: "build/tmp/kotlin-classes/debug/",
37-
excludes: androidExclusion
43+
excludes: reportExclusion
3844
)
3945
def javaMainSrc = "${project.projectDir}/src/main/java/"
4046
def kotlinMainSrc = "${project.projectDir}/src/main/kotlin/"
@@ -43,11 +49,30 @@ task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest']) {
4349
executionData.from = files("${project.buildDir}/outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec")
4450
}
4551

46-
task showCoverageReport(type: Exec, dependsOn: 'jacocoTestReport') {
47-
group = "Reporting"
48-
commandLine "open", "${project.buildDir}/reports/jacoco/jacocoTestReport/html/index.html"
52+
task jacocoTestCoverageVerification(type: JacocoCoverageVerification, dependsOn: 'testDebugUnitTest') {
53+
54+
group = "Verification"
55+
description = "Assert minumun coverage in the project."
56+
57+
sourceDirectories.setFrom jacocoTestReport.sourceDirectories
58+
classDirectories.setFrom jacocoTestReport.classDirectories
59+
executionData.setFrom jacocoTestReport.executionData
60+
61+
violationRules {
62+
rule {
63+
element = 'CLASS'
64+
65+
limit {
66+
counter = 'BRANCH'
67+
minimum = 0.5
68+
}
69+
excludes = validationExclusion
70+
}
71+
}
4972
}
5073

74+
check.dependsOn jacocoTestCoverageVerification
75+
5176
android.testOptions {
5277
unitTests.all {
5378
jacoco {

mylibrary/src/main/java/com/mob1st/mylibrary/Calculator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ data class Calculator(
99

1010
fun div(): Int {
1111
return if (value1 > 0) {
12-
value1 / value2
12+
value1 / value2 * 1
1313
} else throw IllegalStateException("invalid check exception")
1414
}
1515

0 commit comments

Comments
 (0)