public class TestSpring {
@Test
public void test() {
//初始化应用程序上下文对象
ApplicationContext ac = new ClassPathXmlApplicationContext("xxx.xml");
Abc abc = (Abc) ac.getBean("abc");
}
}
使用注解的测试用例
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations=”classpath:xxx.xml”)
@RunWith(SpringJUnit4ClassRunner.class)//让测试运行于spring测试环境
@ContextConfiguration(locations="classpath:xxx.xml")//指定 Spring 配置文件所在的位置
public class TestSpring {
@Resource
private A a;
@Test
public void test() {
}
}