Skip to content

Commit

Permalink
chore: add test coverage
Browse files Browse the repository at this point in the history
add into gradle, git actions (with Jacoco, CodeCov)
  • Loading branch information
junha-ahn committed Jul 9, 2023
1 parent 83e7c96 commit e31ec0f
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
38 changes: 30 additions & 8 deletions .github/workflows/gradle-build-test-lint.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Gradlew build-test-ktlint

on:
pull_request:
push:
branches: [main]
on: [push]

jobs:
build:
Expand All @@ -16,16 +13,41 @@ jobs:
with:
java-version: '17'
distribution: 'temurin'

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@ccb4328a959376b642e027874838f60f8e596de3

- name: Build And Test with Gradle
- name: Build
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
with:
arguments: build -x ktlintMainSourceSetCheck -x ktlintTestSourceSetCheck -x ktlintKotlinScriptCheck
arguments: bootJar

- name: Ktlint check
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
if: always()
with:
arguments: ktlintCheck

- name: Test
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
if: always()
with:
arguments: test -x jacocoTestReport

- name: Jacoco Coverage Report
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
if: always()
with:
arguments: jacocoTestReport -x test -x jacocoTestCoverageVerification

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: always()
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./build/reports/jacoco/test/jacocoTestReport.xml

- name: Jacoco Coverage Verification
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
if: always()
with:
arguments: ktlintCheck
arguments: jacocoTestCoverageVerification
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
jacocoRepost/

HELP.md
.gradle
build/
Expand Down
59 changes: 59 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
kotlin("plugin.allopen") version "1.6.21"
kotlin("plugin.noarg") version "1.6.21"
id("org.jlleitschuh.gradle.ktlint") version "11.5.0"
id("jacoco")
}

group = "com.example"
Expand Down Expand Up @@ -42,6 +43,7 @@ tasks.withType<KotlinCompile> {

tasks.withType<Test> {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}

allOpen {
Expand All @@ -64,3 +66,60 @@ val installLocalGitHook = tasks.register<Copy>("installLocalGitHook") {
tasks.build {
dependsOn(installLocalGitHook)
}

subprojects {
apply(plugin = "jacoco")

jacoco {
toolVersion = "0.8.10"
}
}

tasks.jacocoTestReport {

dependsOn(tasks.test)
reports {
html.isEnabled = true
csv.isEnabled = false
xml.isEnabled = true
html.destination = File("${rootProject.rootDir}/jacocoRepost")
}

finalizedBy(tasks.jacocoTestCoverageVerification)
}

tasks.jacocoTestCoverageVerification {

var Qdomains = mutableListOf<String>()

for (qPattern in 'A'..'Z') {
Qdomains.add("*.Q$qPattern*")
}

violationRules {
rule {
element = "CLASS"

limit {
counter = "BRANCH"
value = "COVEREDRATIO"
// minimum = "0.8".toBigDecimal()
}

limit {
counter = "LINE"
value = "COVEREDRATIO"
// maximum = "0.8".toBigDecimal()
}

// 빈 줄을 제외한 코드의 라인수를 최대 200라인으로 제한합니다.
limit {
counter = "LINE"
value = "TOTALCOUNT"
maximum = "200".toBigDecimal()
}

excludes = Qdomains
}
}
}

0 comments on commit e31ec0f

Please sign in to comment.