DaggerMock icon indicating copy to clipboard operation
DaggerMock copied to clipboard

Android module: Mockito cannot mock/spy because : - final class

Open MarekMacko opened this issue 8 years ago • 4 comments
trafficstars

Hi, I have project with android library where I trying use your library, when I start tests then following error occurs:

org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class com.example.AppModule
Mockito cannot mock/spy because :
- final class

When I change module build.gradle from apply plugin: 'com.android.library' to apply plugin: 'com.android.application' then everythings works.

MarekMacko avatar Nov 21 '17 16:11 MarekMacko

Are you using DexOpener or something else to open classes? Are you using multidex? Thanks for your report

fabioCollini avatar Nov 21 '17 20:11 fabioCollini

Yes, I was using DexOpener and multidex.

MarekMacko avatar Nov 24 '17 01:11 MarekMacko

I am not sure if this is a DaggerMock issue or a DexOpener issue :( Did you try to search for something similar connected to DexOpener?

fabioCollini avatar Dec 04 '17 20:12 fabioCollini

@maras93 Add these dependency if your use Kotlin

androidTestCompile "org.mockito:mockito-android:2.8.8"
androidTestCompile('com.nhaarman:mockito-kotlin-kt1.1:1.5.0') {
        exclude group: 'org.jetbrains.kotlin'
}

charleston10 avatar Feb 21 '18 20:02 charleston10