Using Espresso 2.0 + Roboelectric in an Android project

I already have a bunch of Roboelectric test. I want to add Espresso 2.0 , which was recently introduced.

Roboelectric introduced the deckard gradle project to solve the problem of using Roboelectric and Espresso together. but a solution for Espresso 1.1 that is out of date now.

This is part of my build.gradle file to use Espresso 2.0, while I have Roboelectric, as well as the Espresso 2.0 instruction :

buildscript {
    repositories {
        mavenCentral()
        maven { url 'http://download.crashlytics.com/maven' }
    }

    dependencies {
        classpath 'org.robolectric:robolectric-gradle-plugin:0.13.2'
    }
}

apply plugin: 'com.android.application'
apply plugin: 'robolectric'

android {
    packagingOptions {
        exclude 'LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE'
    }
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
    defaultConfig {
        versionCode 1
        versionName '1.0'
        minSdkVersion 9
        targetSdkVersion 21
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}

robolectric {
    include '**/*Test.class'
    exclude '**/espresso/**/*.class'
}

dependencies {
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'

    androidTestCompile('junit:junit:4.11') {
        exclude module: 'hamcrest-core'
    }
    androidTestCompile('org.robolectric:robolectric:2.4') {
        exclude module: 'classworlds'
        exclude module: 'commons-logging'
        exclude module: 'httpclient'
        exclude module: 'maven-artifact'
        exclude module: 'maven-artifact-manager'
        exclude module: 'maven-error-diagnostics'
        exclude module: 'maven-model'
        exclude module: 'maven-project'
        exclude module: 'maven-settings'
        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-provider-api'
        exclude group: 'com.android.support', module: 'appcompat-v7'
        exclude group: 'com.android.support', module: 'support-v4'
    }
}

But I can not run the Roboelectric and Espresso tests individually. I appreciate any suggestion.

Addenda:

to run roboelectric test : gradlew test
to run espresso: gradlew connectedAndroidTest
+4
2

Android: https://github.com/freezy/android-seed

features:

  • Android Studio
  • IDE ( )
  • Espresso IDE ( )
  • Lollipop compat libs
  • .
+3

, , .

sourceSets {
    androidTest {
        java {
            exclude 'com/company/project/**/*Test.java'
        }
    }
}

gradle.taskGraph.whenReady {taskGraph ->
    def testRunTask = project.tasks.getByName 'testDebug'
    testRunTask.include(['**/*Test.class'])
    testRunTask.exclude(['**/espresso/**/*.class','**/integration/**/*.class'])
}
+1

All Articles