Mockito: Why You Should Not Use InjectMocks Annotation to Autowire Fields – Ted Vinke's Blog
People like the way how Mockito is able to mock Spring's auto-wired fields with the @InjectMocks
annotation. When I read this post of Lubos Krnac last week, I thought I should explain why I think the use of InjectMocks is a bad signal and how you should avoid it. Hint: it's about visibility.
Let's say we have a PlannerServiceImpl
which delegates to a PlannerClient
. Uses Spring for auto-wiring all together; there's no constructor, but Spring is able to use field injection.
Read full article from Mockito: Why You Should Not Use InjectMocks Annotation to Autowire Fields – Ted Vinke's Blog
No comments:
Post a Comment