Mackovich
Mackovich

Reputation: 3573

Mockito: mocking final class in UI tests

So starting with Android P, it is possible to mock final classes for UI / Espresso tests. Great.

After some research, I was using com.linkedin.dexmaker:dexmaker-mockito-inline-extended to be able to mock final classes.

However, it uses and old version of mockito (2.28.0 at the time of writing this post) while Mockito has recently released version 3.15.13.

Up until now I was fine using an old version of Mockito until I stumbled on issues solved in later version.

The following gradle configuration:

androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito-inline-extended:2.28.0"
androidTestImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
androidTestImplementation "org.mockito:mockito-android:3.5.13"

produces this error at compile time:

More than one file was found with OS independent path 'mockito-extensions/org.mockito.plugins.MockMaker'.

I believe I know it means that some dependencies use the same dependency. I tried using exclude but without success.

Has anyone an idea on how to fix that ? Thanks for the help !

Upvotes: 2

Views: 1291

Answers (1)

Jordan Malfara
Jordan Malfara

Reputation: 41

Removing androidTestImplementation "org.mockito:mockito-android:3.5.13" did it for me. They have an issue on their github https://github.com/linkedin/dexmaker/issues/149

Upvotes: 2

Related Questions