Skip to content

Commit

Permalink
[chore #63] Jacoco 세팅하기 (#64)
Browse files Browse the repository at this point in the history
* [chore] : jacoco 의존성 추가
- 테스트 결과 리포트 설정
- 테스트 검증 규칙 설정

* [chore] : 커버리지 하한 수정

* [chore] : Jacoco 결과 출력하는 CI 스크립트 작성

* [fix] : ci파일 경로 수정

* [chore] : ci 스크립트 step name 수정

* [chore] : 빌드, ci 시 커버리지 하한 통일

* [chore] : security 검증 제외

* [chore] : lombok test coverage 제외
hyun2371 authored Aug 21, 2024
1 parent 51e33ea commit fb7a454
Showing 3 changed files with 84 additions and 15 deletions.
32 changes: 18 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,26 +19,22 @@ jobs:
- name: Check the timezone
run: date

# 자바 버전 설정
- name: Set up JDK 17
- name: 자바 버전 17 설정
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'

# test 경로 application.yml 파일 생성
- name: Generate application.yml
- name: test 경로 application.yml 파일 생성
run: |
mkdir -p ./src/test/resources
echo "${{ secrets.TEST_APPLICATION_YML }}" > ./src/test/resources/application.yml
# gradle 권한 부여
- name: Grant execute permission for gradlew
- name: gradle 권한 부여
run: chmod +x ./gradlew
shell: bash

# 빌드 시 캐시 적용
- name: Gradle Caching
- name: 빌드 시 캐시 적용
uses: actions/cache@v3
with:
path: |
@@ -48,19 +44,27 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
# 빌드
- name: Build with Gradle
- name: 빌드
run: ./gradlew build

# 테스트 결과 PR 코멘트에 등록
- name: Register the test results as PR comments
- name: Jacoco Test Coverage Report 코멘트에 등록
id: jacoco
uses: madrapps/jacoco-report@v1.6.1
with:
title: Code Coverage
paths: ${{ github.workspace }}/build/jacocoReport/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 65
min-coverage-changed-files: 65
update-comment: true

- name: 테스트 결과 PR 코멘트에 등록
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: '**/build/test-results/test/TEST-*.xml'

# 테스트 실패시 코드 라인에 대한 체크 추가
- name: If test fail, add check comment on failed code line
- name: 테스트 실패시 코드 라인에 대한 체크 추가
uses: mikepenz/action-junit-report@v3
if: always()
with:
66 changes: 65 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.8'
id 'io.spring.dependency-management' version '1.1.6'
id 'jacoco'
}

group = 'com.dnd'
@@ -23,6 +24,69 @@ repositories {
mavenCentral()
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacoco {
toolVersion = "0.8.12"
reportsDirectory = layout.buildDirectory.dir('jacocoReport')
}

def QDomains = []

for (qPattern in '**/QA'..'**/QZ') {
QDomains.add(qPattern + '*')
}

jacocoTestReport {
dependsOn test

classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, excludes: [
'**/*Application*',
'**/exception/**',
'**/config/**',
'**/dto/**',
'**/s3/**',
'**/security/**'
] + QDomains)
}))

reports {
html.required.set(true)
xml.required.set(true)
csv.required.set(true)
}
}

jacocoTestCoverageVerification {
violationRules {
rule {
enabled = true
element = 'CLASS'

limit {
counter = 'LINE'
value = 'COVERERDRATIO'
minimum = 0.65
}
}

rule {
excludes = [
'**/*Application*',
'**/exception/**',
'**/config/**',
'**/dto/**',
'**/s3/**',
'**/security/**'
] + QDomains
}
}
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
@@ -66,7 +130,7 @@ dependencies {

// mail
implementation 'org.springframework.boot:spring-boot-starter-mail'

//swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'

1 change: 1 addition & 0 deletions lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.addLombokGeneratedAnnotation = true

0 comments on commit fb7a454

Please sign in to comment.