Skip to content
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

When verifying SpykBean's, verification acknowledgement fails #88

Closed
slawek-mazur opened this issue Oct 5, 2022 · 4 comments
Closed

Comments

@slawek-mazur
Copy link

@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
@jnizet
Copy link
Member

jnizet commented Oct 5, 2022

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.

@slawek-mazur
Copy link
Author

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

@jnizet
Copy link
Member

jnizet commented Oct 8, 2022

@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.

@slawek-mazur
Copy link
Author

Fair enough, thanks for the support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants