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

Mocked bean sometimes is not injected #91

Open
mostrovoi opened this issue Oct 26, 2022 · 2 comments
Open

Mocked bean sometimes is not injected #91

mostrovoi opened this issue Oct 26, 2022 · 2 comments

Comments

@mostrovoi
Copy link

Hi,
I am creating some beans programmatically via BeanDefinitionRegistryPostProcessor and postProcessBeanDefinitionRegistry.

The problem I am facing is that for some tests I need to mock one of the beans created programmatically

When using @MockkBean annotation sometimes the mocked bean does replace the original bean while sometimes it does not.

I suspect that the issue is the bean creation via code is too slow and the replacement of the mocked bean happens before the initialization is complete.

Is there any workaround for this?

@medwards-cais
Copy link

Also found this issue recently

@jnizet
Copy link
Member

jnizet commented Nov 11, 2022

There is no way I can answer this question without a complete minimal reproduction. But even then, given that SpringMockk is just a clone of the official Spring Boot Mockito testing support, start by reproducing the issue with Mockito. And if you reproduce it, then ask in Spring Boot channels for help, because it won't be specific to SpringMockK.

If on the other hand you can't reproduce the issue with Spring Boot's native Mockito support, but can reproduce it with SpringMockK, then provide the two reproductions and I'll try to have a look at what's different between SpringMockK and Spring Boot.

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

3 participants