From 5d8c1f10adb5d77269606d7c483db355a5d60425 Mon Sep 17 00:00:00 2001 From: seojin Yoon <90759319+7zrv@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:52:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?cicd:=20CI=EC=8B=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=BB=A4=EB=B2=84=EB=A6=AC=EC=A7=80=20=EC=B8=A1?= =?UTF-8?q?=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Jacoco 의존성 추가 - 테스트 커버리지 측정 옵션 추가 --- build.gradle | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/build.gradle b/build.gradle index ca652bb9c..8972df288 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,12 @@ plugins { id 'org.springframework.boot' version '3.3.5' id 'io.spring.dependency-management' version '1.1.6' id "org.sonarqube" version "5.1.0.4882" + id "jacoco" } + + + group = 'com' version = '0.0.1-SNAPSHOT' @@ -24,12 +28,72 @@ repositories { mavenCentral() } +jacoco { + toolVersion = "0.8.12" +} + +//QueryDSL 제외 패턴 +def QDomains = [] +for (qPattern in '*.QA'..'*.QZ') { // qPattern = '*.QA', '*.QB', ... '*.QZ' + QDomains.add(qPattern + '*') +} + +def jacocoExcludePatterns = [ + // 측정 안하고 싶은 패턴 + "**/*Application*", + "**/*Config*", + "**/*Exception*", + "**/*Request*", + "**/*Response*", + "**/*Dto*", + "**/*Interceptor*", + "**/*Filter*", + "**/*Resolver*", + "**/test/**", + "**/resources/**" +] + +jacocoTestCoverageVerification { + + violationRules { + rule { + // rule 활성화 + enabled = true + + // 클래스 단위로 룰 체크 + element = 'CLASS' + + // 라인 커버리지를 최소 80% 만족 + limit { + counter = 'LINE' + value = 'COVEREDRATIO' + minimum = 0.60 + } + + // 브랜치 커버리지를 최소 80% 만족 + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + minimum = 0.60 + } + + excludes = jacocoExcludePatterns + } + } +} + sonar { properties { property "sonar.projectKey", "prgrms-web-devcourse-final-project_WEB1_1_Bongdari_BE" property "sonar.organization", "prgrms-web-devcourse-final-project" property "sonar.host.url", "https://sonarcloud.io" + property 'sonar.sources', 'src' + property 'sonar.language', 'java' + property 'sonar.test.exclusions', jacocoExcludePatterns.join(',') + property 'sonar.test.inclusions', '**/*Test.java' + property 'sonar.java.coveragePlugin', 'jacoco' + property 'sonar.coverage.jacoco.xmlReportPaths', jacocoDir.get().file("jacoco/index.xml").asFile } } @@ -64,4 +128,29 @@ dependencies { tasks.named('test') { useJUnitPlatform() + finalizedBy 'jacocoTestReport' +} + +def jacocoDir = layout.buildDirectory.dir("reports/") + +jacocoTestReport { + dependsOn test // 테스트가 수행되어야만 report를 생성할 수 있도록 설정 + reports { + html.required.set(true) + xml.required.set(true) + csv.required.set(true) + html.destination jacocoDir.get().file("jacoco/index.html").asFile + xml.destination jacocoDir.get().file("jacoco/index.xml").asFile + csv.destination jacocoDir.get().file("jacoco/index.csv").asFile + } + + afterEvaluate { + classDirectories.setFrom( + files(classDirectories.files.collect { + fileTree(dir: it, excludes: jacocoExcludePatterns + QDomains) // Querydsl 관련 제거 + }) + ) + } + finalizedBy jacocoTestCoverageVerification + } From fbdb09392d62483e8d74f9ba7f458ff312c374cc Mon Sep 17 00:00:00 2001 From: seojin Yoon <90759319+7zrv@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:01:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?cicd:=20Jacoco=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EC=99=B8=20=ED=8C=A8=ED=84=B4=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - config의 테스트 커버리지 제외 패턴 추가 --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 8972df288..3e95e9857 100644 --- a/build.gradle +++ b/build.gradle @@ -49,6 +49,7 @@ def jacocoExcludePatterns = [ "**/*Interceptor*", "**/*Filter*", "**/*Resolver*", + "**/*Entity*", "**/test/**", "**/resources/**" ]