-
|
We've noticed after migrating from MockK to Mokkery that mocks of an interface with method annotations now includes those annotations to the implementation methods. For most cases this isn't an issue, however there are some systems (such as temporal.io) that requires some annotations are only present on the interface and not the implementation. We've having to work around this in our tests now by either Proxying the mock or overriding the interface methods in another interface and mocking that instead. @Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class TestAnno
interface MyInterface {
@TestAnno
fun method()
}
class AnnotationInheritanceTest {
@Test
fun mockk() { // passes
val mock = mockk<MyInterface>()
mock::class.java.methods.find { it.name == "method" }
.shouldNotBeNull().annotations.shouldBeEmpty()
}
@Test
fun mokkery() { // fails
val mock = mock<MyInterface>()
mock::class.java.methods.find { it.name == "method" }
.shouldNotBeNull().annotations.shouldBeEmpty()
}
}Is it possible to make annotation copying configurable either per-mock or project-wide? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Hi, thank you for this question! This is a totally valid use case. I’ve created an issue for it (#126) and should be able to address it in the next release. I’m closing this discussion. If you have anything else to add, please do so in the issue. |
Beta Was this translation helpful? Give feedback.
Hi, thank you for this question! This is a totally valid use case. I’ve created an issue for it (#126) and should be able to address it in the next release.
I’m closing this discussion. If you have anything else to add, please do so in the issue.