I have upgraded my Android Application to kotlin 1.4.10
Now my tests are failing when trying spyk() classes
with this exception
io.mockk.MockKException: Can't instantiate proxy for class com.aaa.bbb.ccc.MyClass
with a strange class cast exception which basically states
cannot cast class com.aaa.bbb.ccc.MyClass to com.aaa.bbb.ccc.MyClass
why is MockK trying to cast a class to itself?
When my gradle test deps resemble this my tests fail:-
def coroutines_version = '1.3.7'
def junit_version = '4.13'
def mockk_version = '1.10.0'
def archtesting_version = '2.1.0'
def unitils_version = '3.4.6'
testImplementation "junit:junit:$junit_version"
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
testImplementation "androidx.arch.core:core-testing:$archtesting_version"
testImplementation "androidx.test:core:1.3.0"
testImplementation "org.unitils:unitils-core:$unitils_version"
testImplementation 'org.robolectric:robolectric:4.4'
testImplementation "org.koin:koin-test:$koin_version"
testImplementation "junit:junit:4.13"
testImplementation "androidx.test.ext:junit:1.1.2"
androidTestImplementation "androidx.test.ext:junit:1.1.2"
androidTestImplementation "androidx.test.espresso:espresso-core:3.3.0"
When I revert back to these deps my tests pass:-
def coroutines_version = '1.3.7'
def junit_version = '4.13'
def mockk_version = '1.10.0'
def archtesting_version = '2.1.0'
def unitils_version = '3.4.6'
testImplementation "junit:junit:$junit_version"
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
testImplementation "androidx.arch.core:core-testing:$archtesting_version"
testImplementation "androidx.test:core:1.2.0"
testImplementation "org.unitils:unitils-core:$unitils_version"
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation "org.koin:koin-test:$koin_version"
testImplementation "androidx.test.ext:junit:1.1.1"
androidTestImplementation "androidx.test.ext:junit:1.1.1"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"