首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Android项目中使用Espresso 2.0 + Roboelectric

在Android项目中使用Espresso 2.0 + Roboelectric
EN

Stack Overflow用户
提问于 2015-01-21 19:34:09
回答 2查看 3.5K关注 0票数 4

我已经做了一堆电子设备的测试。我想添加最近引入的Espresso 2.0

机器人电气引入了deckard-gradle template project来解决机器人电气和意式咖啡一起使用的问题。但是解决方案是Espresso 1.1,它现在已经被弃用了。

这是我的build.gradle文件的一部分,目的是为了使用Espresso2.0,同时我也有Roboelectric以及跟随Espresso 2.0 instruction

代码语言:javascript
复制
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'
    }
}

但是我不能单独运行Roboelectric和Espresso测试。我很感谢你的建议。

附录:

代码语言:javascript
复制
to run roboelectric test : gradlew test
to run espresso: gradlew connectedAndroidTest
EN

回答 2

Stack Overflow用户

发布于 2015-01-31 00:41:20

试试这个android starter项目:https://github.com/freezy/android-seed

它有很多features

在安卓Studio

  • Robolectric测试中,棒棒糖可以很好地加载,并且可以在集成开发环境中调试(对于在集成开发环境中工作和调试的单元testing)

  • Espresso测试,对于准备使用

  • 测试覆盖率的

,适用于functional testing)

  • Latest
  • compat libs
票数 3
EN

Stack Overflow用户

发布于 2015-02-18 03:01:09

我排除了用来完成你想要的测试。

代码语言:javascript
复制
sourceSets {
    androidTest {
        java {
            exclude 'com/company/project/**/*Test.java'
        }
    }
}

代码语言:javascript
复制
gradle.taskGraph.whenReady {taskGraph ->
    def testRunTask = project.tasks.getByName 'testDebug'
    testRunTask.include(['**/*Test.class'])
    testRunTask.exclude(['**/espresso/**/*.class','**/integration/**/*.class'])
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28066216

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档