一、整合Junit
1、环境搭建
(1)导入jar包:基本4+1;测试:spring-test..jar
(2)让Junit通知spring加载配置文件
(3)让spring容器自动进行注入
2、实现代码
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations="classpath:applicationContext.xml")
public class TestApp {
@Autowired //与junit整合,不需要在spring xml配置扫描
private AccountService accountService;
@Test
public void demo01(){
//String xmlPath = "applicationContext.xml";
//ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
//AccountService accountService = (AccountService) applicationContext.getBean("accountService");
accountService.transfer("jack", "rose", 1000);
}
}