jacoco
code coverage를 측정할 때 씀
1. build.gradle의 제일 하단에 (dependencies 밑에) 아래와 같이 추가
apply plugin: 'jacoco'
jacoco {
reportsDir = file("${buildDir}/reports")
toolVersion = '0.8.2'
}
task coverageReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
group = "Reporting"
description = "Generate Jacoco coverage reports"
def coverageSourceDirs = ['src/main/java']
classDirectories = fileTree(
dir: "${buildDir}/intermediates/classes/debug",
excludes: ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'com/android/**/*.class']
)
sourceDirectories = files(coverageSourceDirs)
executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec")
reports {
xml.enabled = true
html.enabled = true
}
}
2. build.gradle 중에서 android {} 안에 다음을 추가
testOptions {
unitTests {
includeAndroidResources = true
}
}
3. 터미널에서
gradlew.bat :app:coverageReport -stacktrace
로 실행
4. app/build/report에 저장됨
유의할점
이상한 널포인트 익셉션이 떴는데
java 8 이상을 쓰고있다면 버전을 낮춰보자
'코딩 > 안드로이드' 카테고리의 다른 글
Android studio code coverage시 Robolectric 사용할 때 ComplexColor 부분 에러 해결 (0) | 2018.09.17 |
---|---|
MVP 패턴 (0) | 2018.09.14 |
심플 프리뷰 메이커 개인정보 처리방침 (0) | 2018.07.29 |
Uri에서 썸네일 가져오기 (0) | 2018.04.29 |
Uri to path, path to Uri (0) | 2018.04.29 |