首页 > 技术文章 > Spring UnitTest

netact 2017-01-23 14:28 原文

demo:https://files.cnblogs.com/files/netact/spring01.zip

 

首先说一下Spring IOC的运行机制,同过xml或者annotation()来将pojo class转换为bean。 然后通过Autowire引入bean 对象进行使用。

所以unittest的关键就是能运行spring,并且让spring框架加载相关的配置文件。

 

1,配置SpringContext.xml

位置/src/main/resources/SpringContext.xml

 

2,unittest 类中启用spring:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:SpringContext.xml")//(classes = AppConfig.class)

推荐阅读