Android Studio (gradle) Cannot Find Mockito
Solution 1:
Try replacing testCompile
with androidTestCompile
, it works for me when importing Mockito libs.
However, you may run to a runtime error if you include only mockito-core. You'll need to add into your gradle:
androidTestCompile "org.mockito:mockito-core:1.10.19"
androidTestCompile "com.google.dexmaker:dexmaker:1.2"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.2"
If you have error with dexcache, put this line into your setUp()
(Assuming you are using InstrumentalTestCase
)
System.setProperty("dexmaker.dexcache", getInstrumentation().getTargetContext().getCacheDir().getPath());
Solution 2:
I was stuck into a similar problem, and adding the mockito jar file manually did the thing for me.
To do that, first create a directory called "libs" in your app directory. Take note that this directory should be in the same level as that of the src/main and build directories. Next, download the mockito jar file and paste it into the libs directory.
Include that into your dependencies in the app level build.gradle file:
dependencies {
compile files('libs/add-your-jar-file-name-here')
}
Sync the gradle and that should do the job.
Refer to this answer for more detailed answer with snapshots.
Solution 3:
androidTestCompile has now been replaced with androidTestImplementation
dependencies {
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
}
Solution 4:
Make sure the test file is located under $your_module/src/test/java
or $your_module/src/androidTest/java
directory.
Post a Comment for "Android Studio (gradle) Cannot Find Mockito"