Intellij 16-单元测试未被确认为android模块项目的一部分

Intellij 16-单元测试未被确认为android模块项目的一部分,android,intellij-idea,android-gradle-plugin,intellij-eap,Android,Intellij Idea,Android Gradle Plugin,Intellij Eap,我正在尝试Intellij 16 EAP,但无法在其中正确导入android项目。机器人分子测试不被视为项目的一部分 我正在导入的项目是一个示例项目,可以在github上找到: 这是build.gradle文件: buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' } }

我正在尝试Intellij 16 EAP,但无法在其中正确导入android项目。机器人分子测试不被视为项目的一部分

我正在导入的项目是一个示例项目,可以在github上找到:

这是build.gradle文件:

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

repositories {
    jcenter()
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.2'

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 23
        versionCode 2
        versionName "1.0.0-SNAPSHOT"
        applicationId "com.example"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    // Support v4
    compile 'com.android.support:support-v4:23.1.1'

    // Espresso
    androidTestCompile 'com.android.support:support-annotations:23.1.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'

    // Robolectric
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    testCompile 'org.apache.maven:maven-ant-tasks:2.1.3' // fixes issue on linux/mac
    testCompile 'org.robolectric:robolectric:3.0'
}
关于为什么会发生这种情况有什么线索吗

编辑: 1) 如果我从gradle中删除所有android插件,只添加java插件,就会立即识别单元测试并将它们添加到project中。然后,只要我切换回android插件,intellij就会再次删除它。
2) 我尝试了Intellij 15和Android Studio 2.0,得到了相同的结果

可能您必须在模块设置中将测试文件夹标记为“测试文件夹”。 Ctrl+alt+shift+S


最好使用金丝雀频道的Android Studio 2.0。它基于Intellij15

经过一番挖掘,我发现这似乎是人们期望的做事方式。您在任何时候都只能在项目中导入检测测试或单元测试。您可以在“build Varians”(构建变体)窗口中的2个选项之间切换


我还发现了这段视频,在15:30描述了这种奇怪的行为。他还表示,它将在Android Studio 2.0中修复,但通过测试,情况正好相反。

为什么不使用Android Studio?AS的最新版本完全支持单元测试。这是一个有其他要求的大型多模块项目。例如其他模块的JavaSpring。Intellij ultimate只是android studio的老大哥,但在android功能方面总是落后2个月。正如android studio在java功能方面落后intellij两个月一样。a)我已经这样做了,但一旦gradle项目被重新导入,模块设置中的更改就会被删除。b) 我更喜欢使用intellij:>test{classpath=project.sourceset.test.runtimeClasspath+文件(“${projectDir}/test”)}或sourceset{test{resources{srcDir“test}}}}我认为问题不在于梯度设置。例如,如果我使用“gradlew test”从命令行运行测试,测试运行良好。这和intellij有关。顺便说一句,我确实试过你提到的,但什么也没发生。我有同样的经历。我似乎不能同时打开两种类型的测试。如果我在构建变体中将其标记为测试源并重新启动,它就可以正常工作。同时穿这两件衣服是行不通的。如果将来能更好地集成,那就太好了。使用IntelliJ 2016.1添加时,必须选择正确的生成变量,以某种方式将文件夹标记为测试源(在项目结构中或右键单击标记为…),然后按重新启动/使缓存无效选项。但每次你想切换测试类型的时候都要这么做,这很烦人,但目前还可行