2015-01-21 36 views
4

我已经有一堆Roboelectric测试。我想添加最近推出的Espresso 2.0在Android项目中使用Espresso 2.0 + Roboelectric

Roboelectric推出了deckard-gradle template project来解决使用Roboelectric和Espresso的问题。但解决方案是现在已弃用的Espresso 1.1。

这是当我有Roboelectric以及以下Espresso 2.0 instruction才能使用咖啡2.0我的build.gradle文件的一部分:

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和咖啡测试。我很欣赏任何建议。

附录:

to run roboelectric test : gradlew test 
to run espresso: gradlew connectedAndroidTest 
+0

我不是在仪器测试方面的专家。但是我认为你甚至可以从工作室对Espresso进行单独测试。要做同样的Robolectric你应该另一个gradle插件(我不使用它,所以不能肯定地说) – 2015-01-22 09:11:06

回答

3

尝试在这个Android启动项目: https://github.com/freezy/android-seed

它有许多features:很好Android Studio中

  • 负载
  • Robolectric测试工作,可调试在IDE中(用于单元测试)
  • 工作和调试的IDE(功能测试)测试特浓
  • 最新棒棒糖COMPAT库准备用
  • 测试覆盖率启用
+0

它的工作原理!谢谢! – 2015-02-02 06:50:10

1

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

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']) 
} 
相关问题