-
Notifications
You must be signed in to change notification settings - Fork 41.2k
ConfigurationProperties with constructor binding cannot be mocked #18652
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
Comments
Interesting data point is that it only fails if |
And I was wrong. It works because the mock does not expose the annotations that are available on the target constructor so the current validation does not apply. |
@sdeleuze Have you got a branch somewhere we can look at? |
@philwebb that wasn't obvious from my previous comment but that's not Kotlin specific as far as I can see. I didn't try with Kotlin so can't say but that's what seems to happen with plain Java, see https://github.com/snicoll-scratches/test-mock-config-props If the annotation is found in both cases, it will fail in both cases whereas this issue is about it not failing at all. If a bean is mocked, the verification should not check for the bind method anyway. |
@philwebb Sadly not anymore, it was on my laptop which was stolen last week. |
:( |
Same thing for me with mockito btw (in kotlin too, not tested in java). |
Configuration properties have not been merged due to error in spring-projects/spring-boot#18652 Closes #35
@sdeleuze @davinkevin I've pushed a fix for this. Could you verify if this works for you? Thanks. |
@mbhave the sample I built for this now works with |
Uh oh!
There was an error while loading. Please reload this page.
I have migrated https://spring.io/guides/tutorials/spring-boot-kotlin/ to Spring Boot
2.2.0.RELEASE
and updated it to leverage immutable configuration properties. As discussed with @snicoll,@ConfigurationProperties
are not scanned by default in test slices, so I have to add to my@WebMvcTest
test either@EnableConfigurationProperties(BlogProperties::class)
or mockBlogProperties
bean.My test works with
@EnableConfigurationProperties(BlogProperties::class)
but fails if I try to mockkBlogProperties
bean (in my case with@MockkBean
from https://github.com/Ninja-Squad/springmockk) with following error:The text was updated successfully, but these errors were encountered: