středa 18. srpna 2010

Injecting Mockito mocks into a Spring bean

I would like to inject a Mockito mock object into a Spring (3+) bean for the purposes of unit testing. My bean dependencies are currently injected by using the @Autowired annotation on private member fields.

Howto do it simple with XML configuration:

<bean id="dao" class="org.mockito.Mockito" factory-method="mock">
    <constructor-arg value="com.package.Dao" />

It's pretty elegant.

Žádné komentáře: