The best way is:
<bean id="dao" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.package.Dao" />
</bean>
Update
In the context file this mock must be listed before any autowired field depending on it is declared.
More Related Contents:
- Where is the @Autowired annotation supposed to go – on the property or the method?
- spring autowiring with unique beans: Spring expected single matching bean but found 2
- Inject and Resource and Autowired annotations
- Spring JSF integration: how to inject a Spring component/service in JSF managed bean?
- Spring @Autowire on Properties vs Constructor
- @Resource vs @Autowired
- How to inject in @FacesValidator with @EJB, @PersistenceContext, @Inject, @Autowired
- Difference between @Mock, @MockBean and Mockito.mock()
- How to inject a Map using the @Value Spring Annotation?
- Injecting a Spring dependency into a JPA EntityListener
- How do I mock an autowired @Value field in Spring with Mockito?
- How to in-memory unit test Spring-Jersey
- Spring: namespace vs contextConfigLocation init parameters in web.xml
- Filter specific packages in @ComponentScan
- How to test a spring controller method by using MockMvc?
- Spring injects dependencies in constructor without @Autowired annotation
- Disable @EnableScheduling on Spring Tests
- Transactional annotation avoids services being mocked
- What is difference between singleton and prototype bean?
- How to inject dependencies into HttpSessionListener, using Spring?
- How does Spring annotation @Autowired work?
- Reuse spring application context across junit test classes
- Spring Expression Language (SpEL) with @Value: dollar vs. hash ($ vs. #)
- Another unnamed CacheManager already exists in the same VM (ehCache 2.5)
- Spring annotation-based DI vs xml configuration?
- Add a Servlet Filter in a Spring Boot application
- Spring JUnit: How to Mock autowired component in autowired component
- Getting Spring Error “Bean named ‘x’ must be of type [y], but was actually of type [$Proxy]” in Jenkins
- Spring HandlerMethodArgumentResolver not executing
- Autowiring in servlet