Wow. These tests are greeeen. You are rocking JUnit and Mockito like nobody’s business. You unit tested the shit out of your code - Uncle Bob would be proud. And it’s time to do more functional testing, so you do Android instrumented test. And then… BAM

org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: interface com.douevencode.Sample Mockito can only mock non-private & non-final classes. If you're not sure why you're getting this error, please report to the mailing list.

If you’re like me you go all

WAT

WAT? I did a lot of Mockiting and I know what I’m doing! I mean, of course kotlin has classes final by default, so maybe it has something to do with this? No, double checked, this is interface. And replicating this with java tests and interfaces doesn’t change anything.

Ok, googling time, people must have similar problem. Their solution? Stick to old Mockito. There is also issue on Mockito’s Github about it: https://github.com/mockito/mockito/issues/1082. There are some very bad workarounds for it. Seriosly, all of this for a little mocking?

Fuck this

And if you are anything like me, you sometimes panic too fast and try too many different things at once. Sometimes it’s enough to read what exception message says (yeah, who does that?). But in that case it would save me time. Solution is simple: replace your mockito dependency with mockito-android dependency.

So instead of:

androidTestCompile 'org.mockito:mockito-core:2.11.0'

you should have:

androidTestCompile 'org.mockito:mockito-android:2.11.0'

Yep, it’s that simple. There is a separate subproject dedicated for Android. None of tutorials I found even mentioned did, everyone used regular Mockito. Even on Mockito website there is:

Use Mockito on Android, thanks to the team working on dexmaker

Nothing about how you need different dependency. Mockito’s Github repo main page is not helpful neither.

Anyway, there you have it. Conclusion? Read your error messages, especially when they come from such great project as Mockito. They probably know better.