New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Abstract method implementations cannot be mocked in Android instrumentation tests #1080
Comments
# Why fix android instrumentation test error: expo-modules-core: https://github.com/expo/expo/actions/runs/4770550299/jobs/8481882792 expo-updates: https://github.com/expo/expo/actions/runs/4785632925/jobs/8509073622 ### expo-modules-core ``` expo.modules.JavaScriptViewModule > should_export_view_prototype[avd-31(AVD) - 12] FAILED io.mockk.MockKException: no answer found for: AppContext(#1).getBackgroundCoroutineScope() at io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:93) expo.modules.JavaScriptViewModule > view_functions_should_be_callable[avd-31(AVD) - 12] FAILED io.mockk.MockKException: no answer found for: AppContext(#2).getBackgroundCoroutineScope() at io.mockk.impl.stub.MockKStub.defaultAnswer(MockKStub.kt:93) ``` ### expo-updates 1. crashes from `mockDelegate.getCheckAutomaticallyConfiguration()` 2. https://github.com/expo/expo/blob/79c05375b8ae9149aa4dff456a3c25641a68f360/packages/expo-updates/android/src/androidTest/java/expo/modules/updates/logging/UpdatesLoggingTest.kt#L106 the line here is two rather than one: # How - [core] answers mocked `getBackgroundCoroutineScope` - [updates] my hypothesis is that mockk cannot [instantiate abstract classes](mockk/mockk#1080). after #22137, the `UpdatesConfiguration.CheckAutomaticallyConfiguration` is now an anonymous class. the workaround here is having a default implementation for `UpdatesConfiguration.CheckAutomaticallyConfiguration.toJSString()`. - [updates] fix `@Before` does not be called in `UpdatesLoggingTest`. in the `@Before` block, the test purges log and will make the test more reliable. # Test Plan ci passed
We got this error when updating |
@MilanVidic thank you so much for pointing this out – I've now realised I was also facing the same issue in my codebase but with a different library (rx-tasks). Resolved by manually excluding the rogue dependency, as detailed in ashdavies/rx-tasks#26 (comment). |
Note: this issue was also raised in the comments of a similar but unrelated issue - #826 (comment)
Expected Behavior
I have some instrumentation tests where I'm mocking a subclass of an abstract class, and attempting to mock an abstract method that it overrides. This actually works just fine on older versions of Mockk (e.g. 1.12.3) but appears to have been broken by the support for value classes added in 1.12.5 (#849).
Current Behavior
The test fails with
java.lang.AbstractMethodError: abstract method "boolean kotlin.reflect.KClass.isValue()"
.Failure Information (for bugs)
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
Context
Failure Logs
Stack trace
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: