Jacoco 설정

코딩하는 하늘토끼·2023년 6월 21일

스프링부트 공부

목록 보기
12/15

프로젝트 환경

종류환경
IDEIntellij IDEA 2023.1.2 (Ultimate Edition)
언어SpringBoot 3.1.0
타입Gradle - Groovy
JDKcorretto-17
패키지 생성Jar
버전관리Github

의존성

종류이름
WebSpring web
Developer ToolsSpring Processor / Lombok
SQLSpring Data JPA / MySQL Driver
기타OpenAPI:2.0.2 / Gson:2.10.1 / Spring test / Jacoco:0.8.7

코드

참조 : gradle에서 jacoco 설정하기
https://techblog.woowahan.com/2661/

build.gradle

plugins {
    id 'jacoco'
}

jacoco {
    toolVersion = "0.8.7"
}

jacocoTestReport {

    dependsOn test // tests are required to run before generating the report

    afterEvaluate {
        classDirectories.setFrom(files(classDirectories.files.collect {
            fileTree(dir: it, exclude: [
                    "**/ProductServiceImpl.class"
            ])
        }))
    }

    reports {
        xml.enabled true
        csv.enabled true
        html.enabled true
    }
}

jacocoTestCoverageVerification {
    violationRules {
        rule {
            enabled = true
            element = 'BUNDLE'
            limit {
                counter = 'INSTRUCTION'
                value = 'COVEREDRATIO'
                minimum = 0.8
            }
            element = 'METHOD'
            limit {
                counter = 'LINE'
                value = 'TOTALCOUNT'
                maximum = 50
            }
            excludes = ['**/ProductServiceImpl.class']
        }
    }
}

test {
    finalizedBy 'jacocoTestReport'
    jacoco {
        enabled = true
        includes = []
        excludes = ['**/ProductServiceImpl.class']
    }
}

Gradle -> project명 -> Tasks -> verification -> test 실행

project명 -> build -> reports -> jacoco -> test -> html -> index.html 열기

실행 화면


0개의 댓글