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
can't find private function inside superclass for dynamic call #425
Labels
Comments
meet the same problem,when can it be fixed? |
Furthermore, when I use |
By the way, one can still verify the call of class Test {
open class Parent {
fun call() {
callPrivate()
}
private fun callPrivate() {}
}
class Child: Parent() {}
@Test
fun testPrivateCall() {
val mock = spyk(Child(), recordPrivateCalls = true)
mock.call()
verify { mock.callPrivateFun("callPrivate") }
}
private fun <T : Any> T.callPrivateFun(funName: String) {
this::class
.superclasses
.map { it.declaredMembers }
.flatten()
.first { it.name == funName }!!
.let {
it.isAccessible = true
it.call(this)
}
}
} |
npars
added a commit
to npars/mockk
that referenced
this issue
Feb 2, 2022
- Add support for mocking non-accessible parent methods using Mockk - The class being mocked is always searched first for the specified method, then all superclasses are checked in no specific order. If multiple superclasses have matching signatures for the method then there is no guarantee which will be mocked first. - Fixes mockk#425
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
should find the private function inside superclass
Current Behavior
can't find function callPrivate() for dynamic call
Context
Failure Logs
io.mockk.MockKException: can't find function callPrivate() for dynamic call
Stack trace
Minimal reproducible code (the gist of this issue)
The text was updated successfully, but these errors were encountered: