Android构建工具1.1.0,单元测试文件夹?

2024-01-02

我最近在我的 android 项目中安装了来自 google 的最新工具:

buildscript {
      repositories {
         jcenter()
         mavenCentral()
      }
      dependencies {
         classpath 'com.android.tools.build:gradle:1.1.0'
      }
}

allprojects {
    repositories {
        jcenter()
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "com.xxx"
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 200
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        debug {
            ...
        }
        release {
            ...
        }
    }
    buildTypes {
        release {
            ...
        }
        debug {
            ...
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'

    // ---- Tests with robolectric
    testCompile 'com.google.guava:guava:14.0.1'
    testCompile 'junit:junit:4.+'
    testCompile 'org.robolectric:robolectric:2.4'
    testCompile 'org.mockito:mockito-all:2.0.2-beta'

    // ---- Tests with Espresso
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') {
        exclude module: 'hamcrest-core'
    }
    androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
    androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
        exclude module: 'hamcrest-core'
    }
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.0'
    androidTestCompile('junit:junit-dep:4.10') {
        exclude module: 'hamcrest-core'
    }
}

之前我用过的地方com.github.jcandksolutions.gradle:android-unit-test:2.1.1在 jvm 中运行我的 robolectric 测试。 正如谷歌对其新构建工具所说:“新的源文件夹被识别为单元测试:src/test/java、src/testDebug/java、src/testMyFlavor/java 等。” 但正如您在下面看到的,我的测试文件夹未被识别为源文件夹。它与com.github.jcandksolutions.gradle:android-unit-test:2.1.1,但使用新的构建工具就不再这样了:

我在这里缺少什么?谢谢


我找到了解决方案,即在 IDE 左上角的 Test Artifacts 之间切换。在此屏幕上,只有“Android Instrumentation Tests”可用,因为我降级了 Android 工具,但使用工具 1.1.0+,您应该会看到不同类型的测试,以使 IDE 将它们识别为源文件夹。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android构建工具1.1.0,单元测试文件夹? 的相关文章