Skip to content

Instantly share code, notes, and snippets.

@briangriffey
Last active August 29, 2015 14:00
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briangriffey/11052289 to your computer and use it in GitHub Desktop.
Save briangriffey/11052289 to your computer and use it in GitHub Desktop.
Gradle pieces needed for robolectric integration in Android Studio
task robolectric(type: Test, dependsOn: assembleRelease) {
testClassesDir = sourceSets.robolectric.output.classesDir
android.sourceSets.main.java.srcDirs.each { dir ->
project.getPlugins().getPlugin('android').prepareTaskMap.each {
sourceSets.robolectric.compileClasspath += files(it.value.explodedDir.getAbsolutePath() + '/classes.jar')
sourceSets.robolectric.runtimeClasspath += files(it.value.explodedDir.getAbsolutePath() + '/classes.jar')
}
def buildDir = dir.getAbsolutePath().split('/')
buildDir = (buildDir[0..(buildDir.length - 2)] + ['build', 'classes', 'release']).join('/')
sourceSets.robolectric.compileClasspath += files(buildDir)
sourceSets.robolectric.runtimeClasspath += files(buildDir)
}
classpath = sourceSets.robolectric.runtimeClasspath
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
androidTest {
java.srcDirs = ['test']
}
}
}
dependencies {
androidTestCompile 'org.robolectric:robolectric:2.2'
androidTestCompile 'org.mockito:mockito-all:1.9.5'
androidTestCompile group: 'junit', name: 'junit', version: '4.+'
androidTestCompile 'com.google.android:android:4.0.1.2'
androidTestCompile files('test-libs/google-play-services.jar')
androidTestCompile ('com.android.support:support-v4:18.0.0')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment