Spring + Junit

来源:互联网 发布:java版的aes加密算法 编辑:程序博客网 时间:2024/06/07 23:13

 导入jar包

       基本 :4+1

       测试:spring-test...jar

 

1.让Junit通知spring加载配置文件

2.让spring容器自动进行注入

 

 修改测试类

@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations="classpath:applicationContext.xml")public class TestApp {@Autowired  //与junit整合,不需要在spring xml配置扫描private AccountService accountService;@Testpublic void demo01(){//String xmlPath = "applicationContext.xml";//ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);//AccountService accountService =  (AccountService) applicationContext.getBean("accountService");accountService.transfer("jack", "rose", 1000);}}


0 0