Reputation: 372
In Android studio gradle can I use Robolectric and Android instrumentation at the same time?
Can anyone tell me on how to do this stuff? To have a test project for robolectric and Android instrumentation at the same time?
Upvotes: 2
Views: 912
Reputation: 7438
There are different approaches to achieve this setup. The most popular is reported by robolectric guys. But I dislike their solution, because of dependency pollution. For details read following post: Android project with Robolectric and Gradle (Android studio)
Upvotes: 1
Reputation: 5507
I've got both tests running in one project.
Execute the Robolectrics tests with gradle test
Execute the Espresso tests with gradle connectedCheck
This is my build.gradle file:
apply plugin: 'android'
apply plugin: 'android-test'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
// tell Android studio that the instrumentTest source set is located in the unit test source set
sourceSets {
androidTest {
setRoot('src/test')
}
}
packagingOptions {
exclude 'LICENSE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
}
lintOptions{
abortOnError false
}
}
androidTest {
include '**/*Test.class'
exclude '**/espresso/*/*.class'
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile fileTree(dir: 'lib', include: ['*.jar'])
// Espresso
androidTestCompile files('lib/espresso-1.1.jar', 'lib/testrunner-1.1.jar', 'lib/testrunner-runtime-1.1.jar')
androidTestCompile 'com.google.guava:guava:14.0.1',
'com.squareup.dagger:dagger:1.1.0',
'org.hamcrest:hamcrest-integration:1.1',
'org.hamcrest:hamcrest-core:1.1',
'org.hamcrest:hamcrest-library:1.1'
androidTestCompile('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestCompile('org.robolectric:robolectric:2.3-SNAPSHOT') {
exclude module: 'classworlds'
exclude module: 'maven-artifact'
exclude module: 'maven-artifact-manager'
exclude module: 'maven-error-diagnostics'
exclude module: 'maven-model'
exclude module: 'maven-plugin-registry'
exclude module: 'maven-profile'
exclude module: 'maven-project'
exclude module: 'maven-settings'
exclude module: 'nekohtml'
exclude module: 'plexus-container-default'
exclude module: 'plexus-interpolation'
exclude module: 'plexus-utils'
exclude module: 'wagon-file'
exclude module: 'wagon-http-lightweight'
exclude module: 'wagon-http-shared'
exclude module: 'wagon-provider-api'
}
androidTestCompile 'com.squareup:fest-android:1.0.+'
}
apply plugin: 'idea'
idea {
module {
testOutputDir = file('build/test-classes/debug')
}
}
Upvotes: 0