Skip to content

Latest commit

ย 

History

History
77 lines (62 loc) ยท 1.78 KB

File metadata and controls

77 lines (62 loc) ยท 1.78 KB

Jacoco

ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€ ์ธก์ • ๋„๊ตฌ

plugins {
    id 'jacoco'
}

test {
    jacoco {
        destinationFile = file("$buildDir/jacoco/jacoco.exec")
    }
    finalizedBy 'jacocoTestReport'
}

jacoco {
    toolVersion = '0.8.5'
}

jacocoTestReport {
    reports {
        html.enabled true
        xml.enabled true    // sonarqube์™€ ์—ฐ๋™์‹œ ํ•„์š”
        csv.enabled false
    }
    finalizedBy 'jacocoTestCoverageVerification'
}

jacocoTestCoverageVerification {
    violationRules {
        rule {
            enabled = true              // rule์— ๋Œ€ํ•œ ์กฐ๊ฑด ์‚ฌ์šฉ ์—ฌ๋ถ€
            element = "CLASS"

            limit {
                counter = "BRANCH"      // ๋ธŒ๋žœ์น˜ ์ปค๋ฒ„๋ฆฌ์ง€
                value = "COVEREDRATIO"
                minimum = 0.70
            }

            limit {
                counter = 'LINE'        // ๋ผ์ธ ์ปค๋ฒ„๋ฆฌ์ง€
                value = 'COVEREDRATIO'
                minimum = 0.70
            }

            limit {
                counter = 'LINE'        // ๋นˆ ์ค„์„ ์ œ์™ธํ•œ ์ฝ”๋“œ์˜ ๋ผ์ธ์ˆ˜๋ฅผ ์ตœ๋Œ€ 200๋ผ์ธ์œผ๋กœ ์ œํ•œ
                value = 'TOTALCOUNT'
                maximum = 200
            }

            excludes = [                // ๋ถ„์„์—์„œ ์ œ์™ธํ•  ํŒŒ์ผ ํŒจํ„ด
//                    '*.test.*',
            ]
        }
    }
}

task testCoverage(type: Test) {
    group 'verification'
    description 'Runs the unit tests with coverage'

    dependsOn(':test',
            ':jacocoTestReport',
            ':jacocoTestCoverageVerification')

    tasks['jacocoTestReport'].mustRunAfter(tasks['test'])
    tasks['jacocoTestCoverageVerification'].mustRunAfter(tasks['jacocoTestReport'])
}

./gradlew testCoverage

https://blog.leocat.kr/notes/2020/02/02/jacoco-config-jacoco-for-kotlin-and-java-project