0

I tried to add some simple Junit to my AndroidStudio project following the Android Tools Project Site - Unit Test Guide.

I created the /src/test/java folder and wrote my simple unit test, finally I added to the build.gradle file

dependencies {
  testCompile 'junit:junit:4.12'
}

The problem is that when I run the test I got build error since the compiler could not find the org.junit.Test import.

The only solution that I found is to change the dependencies line using provided instead of testCompile .

This is the complete gradle.build

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}
apply plugin: 'com.android.application'
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(include: '*.jar', dir: 'libs')
    compile project(':Proj1')
    compile project(':Proj2')
    compile project(':Proj3')
    provided 'junit:junit:4.12'

}

android {

    compileSdkVersion 19
    buildToolsVersion "23.0.1"

    lintOptions {
        disable 'InvalidPackage'
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }


        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }

....
}

What did I do wrong?

Panciz
  • 2,183
  • 2
  • 30
  • 54
  • Can you post your build.gradle file? Do you maybe have a wrong repository configured there? – narko Sep 23 '15 at 11:16
  • I add almost the whole `build.gradle` file – Panciz Sep 23 '15 at 12:30
  • Have a look at [this](http://tools.android.com/tech-docs/unit-testing-support) and make sure you are adding the dependency to the right build.gradle, i.e, the one within the module that refers to your app. – narko Sep 23 '15 at 13:06
  • If you need further info check this out: http://stackoverflow.com/questions/17844957/running-simple-junit-tests-on-android-studio-intellij-when-using-a-gradle-base – narko Sep 23 '15 at 13:09

0 Answers0