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?