demo:http://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)
原文:http://www.cnblogs.com/netact/p/6344007.html