fabioCollini / DaggerMock

A JUnit rule to easily override Dagger 2 objects
Apache License 2.0
1.16k stars 91 forks source link

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

Open MarekMacko opened 6 years ago

MarekMacko commented 6 years ago

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.

fabioCollini commented 6 years ago

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

MarekMacko commented 6 years ago

Yes, I was using DexOpener and multidex.

fabioCollini commented 6 years ago

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?

charleston10 commented 6 years ago

@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'
}