Last active
January 14, 2016 21:43
-
-
Save mr-archano/57cdc4108644cae40d50 to your computer and use it in GitHub Desktop.
The idea is to create an android test module (eg: `tests`) with a dependency on the main android module (eg: `app`). With a little setup you can easily run unit tests (in your `tests/androidTest` folder) on the JVM and hava JaCoCo reports altogether.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Top-level build file where you can add configuration options common to all sub-projects/modules. | |
buildscript { | |
repositories { | |
mavenCentral() | |
jcenter() | |
maven { | |
url "https://oss.sonatype.org/content/repositories/snapshots" | |
} | |
} | |
dependencies { | |
classpath 'com.android.tools.build:gradle:0.12.2' | |
classpath 'org.robolectric:robolectric-gradle-plugin:0.11.+' | |
// NOTE: Do not place your application dependencies here; they belong | |
// in the individual module build.gradle files | |
} | |
} | |
allprojects { | |
repositories { | |
mavenCentral() | |
jcenter() | |
maven { | |
url "https://oss.sonatype.org/content/repositories/snapshots" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'com.android.library' | |
apply plugin: 'robolectric' | |
apply plugin: 'jacoco' | |
jacoco { | |
toolVersion = "0.7.0.201403182114" | |
} | |
android { | |
compileSdkVersion 20 | |
buildToolsVersion "20.0.0" | |
defaultConfig { | |
applicationId "com.archano.groovyplayground" | |
minSdkVersion 14 | |
targetSdkVersion 18 | |
versionCode 1 | |
versionName "1.0" | |
} | |
buildTypes { | |
debug { | |
runProguard false | |
testCoverageEnabled = true | |
} | |
release { | |
runProguard true | |
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | |
testCoverageEnabled = false | |
} | |
} | |
lintOptions { | |
abortOnError false | |
disable 'InvalidPackage' | |
} | |
} | |
dependencies { | |
compile project(':app') | |
androidTestCompile 'junit:junit:4.11' | |
androidTestCompile 'com.squareup:fest-android:1.0.7' | |
androidTestCompile 'org.mockito:mockito-all:1.9.5' | |
androidTestCompile 'org.robolectric:robolectric:2.3' | |
androidTestCompile project(':app').android.applicationVariants.toList().first().javaCompile.classpath | |
androidTestCompile project(':app').android.applicationVariants.toList().first().javaCompile.outputs.files | |
androidTestCompile files(project(':app').plugins.findPlugin("android").getBootClasspath()) | |
} | |
robolectric { | |
// configure the set of classes for JUnit tests | |
include '**/*Test.class' | |
// configure max heap size of the test JVM | |
maxHeapSize = "2048m" | |
} | |
jacoco { | |
toolVersion = "0.7.1.201405082137" | |
} | |
task robolectricReports(type: JacocoReport, dependsOn: "testDebug") { | |
group = "Reporting" | |
description = "Generate Jacoco coverage reports" | |
classDirectories = fileTree( | |
dir: '../app/build/intermediates/classes/debug', | |
excludes: ['**/R.class', | |
'**/R$*.class', | |
'**/*$ViewInjector*.*', | |
'**/BuildConfig.*', | |
'**/Manifest*.*'] | |
) | |
def coverageSourceDirs = ['../app/src/main/java'] | |
additionalSourceDirs = files(coverageSourceDirs) | |
sourceDirectories = files(coverageSourceDirs) | |
executionData = files('../tests/build/jacoco/testDebug.exec') | |
reports { | |
xml.enabled = true | |
html.enabled = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment