2

I am trying Intellij 16 EAP and I can't properly import an android project in it. The robolectric tests are not recognized as part of the project

enter image description here

The project I am importing is a sample project that can be found on github:

https://github.com/robolectric/deckard

This is the build.gradle file:

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'
}

Any clues on why this is happening ?

Edit: 1) If I remove all the android plugin from gradle and I just add the java plugin, instantly recognizes the unit tests and adds them to project. Then as soon as I switch back to android plugin, intellij deletes it again. 2) I tried Intellij 15 and Android Studio 2.0 and I am getting the same results

sakis kaliakoudas
  • 2,039
  • 4
  • 31
  • 51
  • 1
    Why aren't you using Android Studio? The latest version of AS fully supports unit testing. – EJK Jan 06 '16 at 18:29
  • 1
    This is a big multi-module project that has other requirements. Such as java spring for other modules. Intellij ultimate is just the big brother of android studio, but is always 2 months behind with regards to android features. The same way that android studio is 2 months behind intellij with regards to java features. – sakis kaliakoudas Jan 06 '16 at 21:11

2 Answers2

1

Probably you have to mark test folder as "test folder" in module settings. Ctrl+alt+shift+S enter image description here

Also better use Android Studio 2.0 from canary channel. It is based on Intellij 15.

Mistic92
  • 120
  • 3
  • 12
  • a) I have done this, but as soon as the gradle project gets reimported the change in module settings is removed. b) I prefer using intellij :> – sakis kaliakoudas Jan 06 '16 at 21:12
  • test { classpath = project.sourceSets.test.runtimeClasspath + files("${projectDir}/test") } or sourceSets { test { resources { srcDir "test" } } } – Mistic92 Jan 07 '16 at 12:08
  • I don't think that the problem lies in gradle settings. If I run the tests from the command line with "gradlew test" for example the tests run fine. It's something to do with intellij. P.S. I did try what you mentioned but nothing happened – sakis kaliakoudas Jan 07 '16 at 14:27
1

After a bit of digging, I have found that this seem to be the expected way of doing things. You can only have either the instrumentation tests or the unit tests imported in the project at any time. You can switch between the 2 in the "build variants" window.

enter image description here

I also found this video https://www.youtube.com/watch?v=vdasFFfXKOY&index=3&list=LLM9iluZir-2dWQTQ-WfJdbw where in 15:30 this weird behaviour is described. He also says that it will be fixed in Android Studio 2.0 but by test shows the opposite.

sakis kaliakoudas
  • 2,039
  • 4
  • 31
  • 51
  • I'm having the same experience. I can't seem to have both types of tests open. If i mark it as a test source in build variants and I restart it works fine. Having both on at the same time won't work. It'll be nice to have it better integrated in the future. Using IntelliJ 2016.1 – ObjectiveTruth Mar 26 '16 at 14:31
  • To add, you must select the correct build variant, mark the folder as a test source somehow (in project structure or right click mark as..) then press the restart/invalidate cache option. But gotta do this everytime you want to switch test types which is annoying but workable for now – ObjectiveTruth Mar 26 '16 at 14:41