Skip to content

Commit

Permalink
added test gradle task
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemNurtdinov committed Aug 21, 2020
1 parent 0cd80fa commit c24558d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
.externalNativeBuild
app/src/main/aidl/
app/*.apk
/.idea/
/.idea/

# ignore jacoco coverage reports
/coverage
1 change: 1 addition & 0 deletions feature-account-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply from: '../tests.gradle'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand Down
1 change: 1 addition & 0 deletions feature-onboarding-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply from: '../tests.gradle'

android {
compileSdkVersion rootProject.compileSdkVersion
Expand Down
107 changes: 107 additions & 0 deletions jacoco.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
apply plugin: 'jacoco'

jacoco {
toolVersion = "0.8.4"
}

tasks.withType(Test) {
jacoco.includeNoLocationClasses = true
}

afterEvaluate {

task jacocoTestReport(type: JacocoReport) {
outputs.cacheIf { true }

Task runTestsTask

group "Reporting"
description "Generate Jacoco coverage reports."

print "configuring jacoco for project: ${project.name}"

if (project.tasks.findByName('testDevelopDebugUnitTest')) {
runTestsTask = project.tasks.findByName('testDevelopDebugUnitTest')
} else {
runTestsTask = project.tasks.findByName('testDebugUnitTest')
}


dependsOn runTestsTask

def outputFileName = "coverage/coverage-${project.name}.xml"
def outputFileNameHtml = "coverage/coverage-${project.name}.html"

def file = new File("coverage/")
if (!file.exists()) file.mkdirs()

reports {
xml.enabled = true
html.enabled = true
html.setDestination(new File(outputFileNameHtml))
xml.setDestination(new File(outputFileName))
}

outputs.upToDateWhen { false }

def javaClasses = []
def kotlinClasses = []
def sourceDirs = []
def execution = []

def fileFilter = ['**/R.class',
'**/R$*.class',
'**/BuildConfig.*',
'**/Manifest*.*',
'**/*Test.*',
'**/*Activity.*',
'**/*Fragment.*',
'**/*Adapter.*',
'**/*Holder.*',
'**/*App.*',
'**/*Application.*',
'**/*Dialog.*',
'**/*Ext.*',
'**/*ViewPager.*',
'**/*Module.*',
'**/*Dependencies.*',
'**/*Router.*',
'**/*Component.*',
'**/*ViewModelFactory.*',
'**/*Api.*',
'**/*Dao.*',
'android/**/*.*',
'**/com/google/protobuf/**/*.*',
'**/com/google/api/*.*',
'**/data/db/dao/*.*',
'**/android/databinding/layouts/*.*',
'**/androidx/databinding/library/baseAdapters/*.*',
'**/*Activity.*',
'**/*Fragment.*',
'**/di/**',
'**/view/**',
]

javaClasses << fileTree(dir: "$buildDir/intermediates/javac/debug", excludes: fileFilter)

kotlinClasses << fileTree(dir: "$buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)

sourceDirs << fileTree(dir: "$projectDir/src/main/java", excludes: fileFilter)

execution << fileTree(dir: buildDir,
includes: ["jacoco/${runTestsTask.name}.exec",
'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])

executionData.setFrom(files(execution))
sourceDirectories.setFrom(files([sourceDirs]))
classDirectories.setFrom(files([javaClasses, kotlinClasses]))

doFirst {
print "generating jacoco report for project: ${project.name} \n"
print "sourceDirs = " + sourceDirs + '\n'
print "execution = " + execution + '\n'
print "classDirectoriesJava = " + javaClasses + '\n'
print "classDirectoriesKT = " + kotlinClasses + '\n'
}
}
}
16 changes: 16 additions & 0 deletions tests.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apply from: '../jacoco.gradle'

afterEvaluate {
task runModuleTests {
Task runTestsTask
if (project.tasks.findByName('testDevelopDebugUnitTest')) {
runTestsTask = project.tasks.findByName('testDevelopDebugUnitTest')
} else {
runTestsTask = project.tasks.findByName('testDebugUnitTest')
}

dependsOn runTestsTask

group "Verification"
}
}

0 comments on commit c24558d

Please sign in to comment.