Our application is in development process where we are following MVP approach to provide better test coverage by writing unit test cases on our presenter.
Prior to Android P, our test cases were executing without any problem but now after Android P release when we are trying to run test cases on Pixel 2 (Android P), our test cases are failing on following line of code-
private lateinit var mPackageInfo: PackageInfo
mPackageInfo = Mockito.mock(PackageInfo::class.java)
with following error message -
org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class android.content.pm.PackageInfo.
Mockito can only mock non-private & non-final classes.
Underlying exception : java.lang.IllegalArgumentException: On Android P, a class injection can only be applied to BaseDexClassLoader: net.bytebuddy.dynamic.loading.MultipleParentClassLoader@a3838ec
How can i resolve this issue?
By refering to here https://github.com/mockito/mockito/issues/1376
Try to use the version 2.18.3
testImplementation 'org.mockito:mockito-core:2.18.3'
androidTestImplementation 'org.mockito:mockito-android:2.18.3'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With