Search code examples
javaspringjuniteasymock

EasyMock and @Value annotation


In EasyMock - you can mock an Autowired bean with the @Mock annotation Is it possible to mock a value in Spring that is set using the @Value annotation using EasyMock without a setter method?


Solution

  • EasyMock has nothing to do with @Autowired, it injects mocks based on the field names - see http://easymock.org/api/org/easymock/EasyMockSupport.html#injectMocks-java.lang.Object- .

    I guess the test still needs to provide some value to the field annotated woth @Value, so it's easy to do it programmatically in your @Before method.