(+) jacoco
๊ฐ์ธ์ ์ผ๋ก ๋จ์ํ ํ ์คํธ ์ปค๋ฒ๋ฆฌ์ง ํผ์ผํธ๊ฐ ๋๋ค๊ณ ํด์ 'ํ ์คํธ ์ฝ๋๊ฐ ์ ์ง์ฌ์ ธ ์๋ค'๊ณ ๋งํ ์๋ ์๋ค๊ณ ์๊ฐํ๋ค. jacoco ๊ฐ ์ค์ ๋ก ๋ง์ ๋์์ด ๋๋์ง๋ ์ ๋ชจ๋ฅด๊ฒ ๋ค. ๊ฐ์ธ์ ์ผ๋ก ์ค๋ฌด์์๋ ํ๋์ ํ๋ก์ ํธ์ ์ ์ฉ๋์ด ์์๋๋ฐ, ํน๋ณํ ์ผ์ ํผ์ผํธ ๋ฐ์ผ๋ก ๋น๋๊ฐ ์คํจํ๊ฒ ํ๋ค๋๊ฐ ํ๋ ์์ผ๋ก ์ฌ์ฉํ์ง๋ ์์์๋ค.
์ผ๋จ ์์ ์ ์ค์ต์ผ๋ก ์ธํ ํด๋ ์ฝ๋๊ฐ ์์ด์ ์ฌ๊ธฐ ์ฒจ๋ถํ๋ค. gradle document ์๋ ์๋ด๊ฐ ๋์ด์๋ค.
plugins {
id 'org.springframework.boot' version '2.4.5'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'jacoco'
}
group = 'me.fistkim101'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
}
jacoco {
toolVersion = "0.8.6"
}
jacocoTestReport {
reports {
xml.enabled false
csv.enabled false
html.destination layout.buildDirectory.dir('jacocoHtml').get().asFile
}
dependsOn test // tests are required to run before generating the report
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'mysql', name: 'mysql-connector-java', version: '8.0.22'
testImplementation group: 'org.testcontainers', name: 'mysql', version: '1.15.3'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.15.2'
}
test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}
์ด๋ ๊ฒ ํด๋๋ฉด test ๋ผ๋ Task ๊ฐ jacocoTestReport์ ์ฐ๊ฒฐ๋๋ค. ์ฆ test๋ฅผ ์คํํ๋ฉด test -> jacocoTestReport ๋ก task์ ์์กด์ฑ์ด ๋งบ์ด์ ธ์ ์๋์ผ๋ก ํ๋ฆ์ด ์ด์ด์ง๋ค. ๊ทธ๋์ test๋ฅผ ํ ๋๋ง๋ค build > jacocoHtml > index.html ์ด ์๋ก ๊ฐฑ์ ๋๊ณ , ์ฌ๊ธฐ์ ์ฝ๋ ์ปค๋ฒ๋ฆฌ์ง๋ฅผ ์ ์ ์๋ค.

์๋ฆฌ๋ jacoco๊ฐ ๋ฐ์ดํธ์ฝ๋๋ฅผ ์ฝ์ด์ ์ฝ๋ ์ปค๋ฒ๋ฆฌ์ง๋ก ์ฒดํฌํด์ผํ ํฌ์ธํธ๋ฅผ ์ธ์ด ๋๊ณ ํ ์คํธ์ ํด๋น ํฌ์ธํธ๋ฅผ ์ง๋๊ฐ๋์ง๋ฅผ ์ฒดํฌํด์ ์ด๊ฑธ ๋ฐฑ๋ถ์จ๋ก ๋ณด์ฌ์ฃผ๋ ๊ฒ์ด๋ค.
ํ๋ก์ ํธ ๋น๋ ์ JaCoCo ํ๋ฌ๊ทธ์ธ ๋๋ ์ค์ ์ ์ ์ฉํฉ๋๋ค. ์ด๋ฅผ ํตํด ์ปดํ์ผ๋ ํด๋์ค ํ์ผ์ JaCoCo์ ์์ด์ ํธ(agent)๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค.
JaCoCo ์์ด์ ํธ๋ JVM์ ์ฐ๊ฒฐ๋์ด ํด๋์ค ํ์ผ์ด ๋ก๋๋๋ ์์ ์ ๋ฐ์ดํธ ์ฝ๋๋ฅผ ์กฐ์ํฉ๋๋ค. ์ด ๋, ์ถ๊ฐ์ ์ธ ์ฝ๋๋ฅผ ์ฝ์ ํ์ฌ ์ฝ๋ ์ปค๋ฒ๋ฆฌ์ง ์ ๋ณด๋ฅผ ์์งํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
ํ๋ก๊ทธ๋จ์ด ์คํ๋๋ ๋์ JaCoCo ์์ด์ ํธ๋ ์ฝ๋ ์ปค๋ฒ๋ฆฌ์ง ์ ๋ณด๋ฅผ ์์งํ๊ณ , ์ด๋ฅผ ๋ณด๊ณ ์๋ก ์ถ๋ ฅํ๊ฑฐ๋ ๋ค๋ฅธ ๋๊ตฌ์ ํตํฉํ์ฌ ๋ถ์ํ ์ ์์ต๋๋ค.

์ด๋ ๊ฒ ๊ฑฐ์ณ๊ฐ ๋ถ๋ถ์ ์ด๋ก์, ๊ฑฐ์ณ๊ฐ์ง ์์ ๋ถ๋ถ์ ๋นจ๊ฐ์์ผ๋ก ์ฝ๋๋ฅผ line by line ์ผ๋ก ๋ณด์ฌ์ค๋ค. ๋ ธ๋์์ ๋ถ๊ธฐ๋ฌธ์์ ์ผ๋ถ๋ง ํ ์คํธ๊ฐ ๋์์ ๋์ ๋ ธ๋์ ๋ค์ด์๋ชฌ๋๊ฐ ๋์จ๋ค.
Last updated