I am using Android Studio with Gradle, and I am trying to use Mockito in my unit tests. The problem is that I receive the following errors when I run the tests:
Error:Execution failed for task ':app:compileDebugJava'.
Compilation failed; see the compiler error output for details.
Error:(9, 19) error: package org.mockito does not exist
Error:(11, 26) error: package org.mockito does not exist
Error:(19, 9) error: cannot find symbol variable MockitoAnnotations
My build.gradle
file is nothing more than the default with the Mockito dependencies added:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// You must install or update the Support Repository through the SDK manager to use this dependency.
compile 'com.android.support:appcompat-v7:19.+'
////////////////////////////////////////////////
// These are the only lines I added:
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
////////////////////////////////////////////////
}
Then, the lines in my code that are causing the error are just these imports:
import org.mockito.MockitoAnnotations;
import static org.mockito.Mockito.*;
The explanations I've found online all say that the .jar is missing from the CLASSPATH. As far as I understand, Gradle should automatically add the dependencies to the CLASSPATH. Is this correct?
Just to make sure I didn't have to add the jar manually, I also attempted updating the CLASSPATH in my .bashrc
file, but this did not work:
export CLASSPATH=/home/myusername/my/jar/path/mockito-all-1.9.5.jar:$CLASSPATH
What am I doing wrong?