Being a responsible devloper (sic) I like to add unit and instrumentation tests when I add or change code. For reasons Mockito disappeared from my Android instrumentation tests this morning. My project is set up as a library module and an application module that uses the library. Read on to find out how to fix issues like this.
To cut a long story short, this happened when I changed the build variant of the application module to release, as shown below.
There are a lot of issues tagged with androidTest on Google’s tracker. They are aware of the issue and a fix will come but let’s work around it now.
I’m currently using:
- Android studio 1.0
- Android plugin 1.1.0
- Gradle 2.2.1
- Build tools 22.0.1
The first workaround is to set both build variants back to debug. The second one will allow you to use whatever build variant you like. Open up the build.gradle and for each androidTestCompile line you have, add a provided scope for it. Change it from:
provided 'org.mockito:mockito-core:1.10.19' androidTestCompile 'org.mockito:mockito-core:1.10.19'
Yes, I know it seems wrong but it at least it works!