我想在我的IT中使用Springockito模擬DAO bean。在我的IT中,我必須使用spring context.xml來自動調用一些服務,還需要使用mockApplication.xml來模擬DAO。那麼,我怎樣才能同時使用xml配置文件呢?Springockito如何?
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath*:/MockApplicationContext.xml"})
public class PayRollComponentFacadeIT {
@Autowired
IPayRollComponentFacade payRollComponentFacade;
@ReplaceWithMock
@Autowired
IPayRollPersistenceManager payRollPersistenceManager;
我已經包括模擬背景爲@ContextConfiguration(loader = SpringockitoContextLoader.class, locations = {"classpath*:/MockApplicationContext.xml"})
但我必須包括Spring上下文也@ContextConfiguration(locations = {"classpath*:/testApplicationContext.xml"})
問候 Rajib
'@ Autowired'之前'@ ReplaceWithMock'是必需的! – MariuszS
'@ Autowired'僅在情況下,你需要直接在測試用例類訪問嘲笑實例所需。如果你只是需要在春天的上下文中用模擬來替換bean,這並不是必需的。然後所有其他豆都會獲得模擬版本。這是Springockito的註解中最涼爽的特點。 – Vadzim
哇,很好的功能,謝謝:) – MariuszS