How do I mock an autowired @Value field in Spring with Mockito?

You can use the magic of Spring’s ReflectionTestUtils.setField in order to avoid making any modifications whatsoever to your code. The comment from Michał Stochmal provides an example: use ReflectionTestUtils.setField(bean, “fieldName”, “value”); before invoking your bean method during test. Check out this tutorial for even more information, although you probably won’t need it since the method … Read more