Update: Its a bug and it\'s been reported, please star: https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330
<Some things you should check -
It looks like Gradle is not doing it's job.
Manually adding the jars fixed the problem.
Download (junit-4.12.jar) from
https://github.com/junit-team/junit4/wiki/Download-and-Install
and copy it in your libs folder:(yourProjectFolder/app/libs
)
and then in build.gradle(Module: app
) use this codes:
dependencies {
...
compile files('libs/junit-4.12.jar')
...
}
then rebuild your project.
I changed TestCompile to androidTestCompile and it's worked without problems.
testCompile 'junit:junit:4.12'
to
androidTestCompile 'junit:junit:4.12'
add this dependency to solve your issue
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
My tests are in src/test/java
folder and adding test.setRoot('test')
to sourceSets
worked for me.
sourceSets {
test.setRoot('test')
}