2

I have a multi-module Android gradle project which I run in IntelliJ 14.1.4. In the app module of my project, I have some unit tests. The build.gradle file of app project looks like follows:

build.gradle (app)

...

sourceSets {
    main {
        java.srcDirs = ['src']
        res.srcDirs = ['res']
        jniLibs.srcDirs = ['jniLibs']
    }
    test {
        java.srcDirs = ['tests']
    }
}

dependencies {
    ...
    testCompile 'org.powermock:powermock-mockito-release-full:1.6.2'
    testCompile 'junit:junit:4.11'
    testCompile 'org.mockito:mockito-all:1.10.19'
}

directory structure (app)

--app/
-----src/
-----res/
-----tests/
-----jniLibs/

I am using android gradle build tool version 1.2.3 (which is newer than 1.1.0 as suggested by IntelliJ to enable unit testing).

Even with these settings I am unable to get the unit testing under test artifacts in build variants window. What is wrong?

Bhoot
  • 2,614
  • 1
  • 19
  • 36

3 Answers3

1

The trick is to use android gradle build tool version 1.3.1 (or above). Include this line in the top level build.gradle file:

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

And magically, 'Unit Tests' will start appearing under 'Build Variants' window.

Bhoot
  • 2,614
  • 1
  • 19
  • 36
1

added this in the gradle and it fixed the issue for me.

dependencies {
    ...
    testCompile 'junit:junit:4.12'
}
Nakul Sudhakar
  • 1,574
  • 1
  • 24
  • 24
0

I had to restart IntelliJ after creating the test folders.

Kevin Brotcke
  • 3,765
  • 26
  • 34