How about using @Configuration
class? If you're not familiar with this method - you can declare a class that replaces the XML context file and looks something like this:
@Configuration
@ComponentScan({ "com.project.dao"})
public class TestConfiguration {
@Bean
public GenericDao getGenericDao() {
return new MockGenericDaoImpl();
}
}
In the @ComponentScan
annotation just put the relevant packages to scan. This way you're very flexible with the beans you're creating and the way to create them. You can injects mock to the beans whatever way you'd like.
Also you can create several test configurations, each configuration for a different purpose. In order to load the context you need to put this annotation on your test class:
@ContextConfiguration(classes={TestConfiguration .class})