我用SpringTest和EasyMock的做我的Spring bean的單元測試。SpringTest和afterPropertiesSet方法
我的測試bean是這樣的:
@ContextConfiguration(locations = "classpath:/test/applicationContext-test.xml")
public class ControllerTest {
@Autowired
private Controller controller;
@Autowired
private IService service;
@Test
public void test() {
}
}
這裏是我的控制器:
@Controller
@Scope("request")
public class Controller implements InitializingBean {
@Autowired
private IService service;
void afterPropertiesSet() throws Exception {
service.doSomething();
}
}
的方法的afterPropertiesSet初始化時的bean被自動由Spring調用。我想用EasyMock來調用doSomething方法。
我雖然這樣做在我的測試方法,但之前在我的測試方法去,因爲春天時,它初始化豆調用它的afterPropertiesSet方法被執行。
如何,我可以嘲笑我的服務存在於的afterPropertiesSet方法與SpringTest或EasyMock的?
感謝
編輯:
我指定的嘲笑服務被正確地加載在我的控制器由Spring。我的問題不是如何創建模擬(它已經可以),而是如何模擬該方法。
更新我的問題更加全面。 – Kiva