Ninja-Squad/springmockk

When verifying SpykBean's, verification acknowledgement fails

slawek-mazur opened this issue · 4 comments

@SpykBean
private lateinit var serviceHelper: ServiceHelper

in test

confirmVerified(serviceHelper)
can't find stub ServiceHelper(serviceHelper#1)
io.mockk.MockKException: can't find stub ServiceHelper(serviceHelper#1)
	at app//io.mockk.impl.stub.StubRepository.stubFor(StubRepository.kt:16)
	at app//io.mockk.impl.recording.CommonVerificationAcknowledger.acknowledgeVerified(CommonVerificationAcknowledger.kt:25)
	at app//io.mockk.MockKDsl.internalConfirmVerified(API.kt:277)
	at app//io.mockk.MockKKt.confirmVerified(MockK.kt:319)

it works perfectly fine when

@MockkBean
private lateinit var serviceHelper: ServiceHelper

Hi @slawek-mazur

My guess is that it's the same issue as #85. But I'm still waiting for a minimal repro or test case allowing me to debug (and hopefully fix) the issue.
Please take some time to provide one.

hello.

sure thing, please take a look at this minimal PoC

https://github.com/slawek-mazur/mockk-spykbean

it is indeed related to that enrichment $$EnhancerBySpringCGLIB$$ where CustomService becomes com.example.demo.CustomService$$EnhancerBySpringCGLIB$$

if I comment out like so 👇 there's no AOP and CGLIB doesn't kick in with it's proxies.

@Configuration
//@EnableAsync
class ExecutorConfig

@slawek-mazur thanks for the repro. You're indeed hitting the same issue with AOP-modified Spring beans which exists since day 1 (see the first limitation listed in the README), and that I have no idea how to fix. Sorry for that.

There's a test case, BTW, that comes from Spring Boot and which is disabled because it fails, see https://github.com/Ninja-Squad/springmockk/blob/master/src/test/kotlin/com/ninjasquad/springmockk/SpyBeanWithAopProxyTests.kt#L39).

In your specific case, you should be able to workaround the issue by using confirmVerified(AopTestUtils.getUltimateTargetObject(service)) or confirmVerified(AopTestUtils.getTargetObject(service)). But this is a hack.

Unless someone can finally find a solution for this, my only advice would be to find a workaround. I generally thend to avoid spies in the first place.

Fair enough, thanks for the support.