I have webApplication based on SpringMVC and all beans are difined through annotations. Today I try to write test for my controllers. I put first one and tried to mock service which are used in this controllor. All this I did on the following way:
1) create context file for test clientControllerTest-context.xml
<import resource="classpath:spring-context.xml" />
<bean id="ConnectionDB" name="ConnectionDB" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="biz.podoliako.carwash.services.impl.ConnectDB" />
</bean>
where spring-context.xml is a main context file which are used in my webApplication (including information about real ConnectionDB bean)
2)create test class with following configuation
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:controllers/clientControllerTest-context.xml"})
@WebAppConfiguration
when the test was run, the NoUniqueBeanDefinitionException exeption was catched. I hoped that spring overwrite bean ConnectionDB but in fact it found 2 beans with one name and spring cannot chose which one has to be used.
Please, explaine me how can I use my main spring-context and mock one of the bean for testing and avoiding NoUniqueBeanDefinitionException if it possibe ofcause.
NB: I think createing context with all configuration for test is a bad idea therefore I try to use my main spring-context.