Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockito mocks run actual Android code in Lollipop or greater

So I have a Database class that has a dependency that extends SQLOpenHelper and I am testing using Android instrumented tests and Mockito to mock dependencies. We are noticing that Mockito isn't actually mocking the implementations when doing Mockito.mock(class) instead the actual code is running and throwing null pointer exceptions as we would expect. On API 19 devices the tests run as expected and the mocks work correctly.

Does anyone have any suggestions or things to try? I've tried real devices and emulators with similar results. Could this be a Mockito issue, or a dex-maker issue? I haven't found any information while searching for it.

After some more testing any class I mock with Mockito actually just uses the implementation. Here are my dependencies

androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

Note: This is also in a library module if that makes any difference.

like image 381
Stampede10343 Avatar asked Jan 06 '17 13:01

Stampede10343


1 Answers

So getting rid of our old Mockito dependencies and dexmaker and using the new: Mockito-android

Fixed our issues

like image 116
Stampede10343 Avatar answered Nov 09 '22 07:11

Stampede10343