Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将设备仪器化测试添加到具有机器人分子测试的项目中_Android_Gradle_Robolectric_Robolectric Gradle Plugin - Fatal编程技术网

Android 将设备仪器化测试添加到具有机器人分子测试的项目中

Android 将设备仪器化测试添加到具有机器人分子测试的项目中,android,gradle,robolectric,robolectric-gradle-plugin,Android,Gradle,Robolectric,Robolectric Gradle Plugin,我有一个Android项目,它使用Robolectric进行测试。build.gradle的相关部分如下所示: apply plugin: 'robolectric' robolectric { include '**/*Test.class' } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') androidTestCompile 'org.hamcrest:hamcrest-int

我有一个Android项目,它使用Robolectric进行测试。build.gradle的相关部分如下所示:

apply plugin: 'robolectric'

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

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')

    androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
    androidTestCompile('junit:junit:4.12') {
        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'
    }
    androidTestCompile 'com.android.support:support-v4:21.0.3'
}
所有的机器人测试都在
src/androidTest/java/my/package/*Test.java
中。这一切都非常有效。我可以作为普通Gradle构建的一部分运行测试,或者通过IntelliJ的JUnitGUI运行测试


现在我需要添加一些不能使用Robolectric的测试,需要在真正的Android设备上运行。考虑到我已经不得不使用
androidTest
变量进行机器人测试,我如何才能将我的仪器测试添加到此项目中,并且仍然允许机器人测试在没有设备的情况下运行?

这是一种超过时的设置,我建议:

  • 使用最新的stableandroidgradle插件:

    buildscript {
      dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
      }
    }
    
    //apply plugin: 'robolectric'
    
    //robolectric {
    //    include '**/*Test.class'
    //}
    
  • 移除Robolectricgradle插件:

    buildscript {
      dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
      }
    }
    
    //apply plugin: 'robolectric'
    
    //robolectric {
    //    include '**/*Test.class'
    //}
    
  • 将测试源移动到
    test
    文件夹

  • androidTestCompile
    更改为
    testCompile
  • 现在,您可以使用
    /gradlew testDebugUnitTest
    运行测试。您可以将仪器测试添加到
    androidTest
    文件夹中

    考虑将Robolectric升级到
    3.1
    版本