我想在我的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