javaspring整合junit操作(有详细的分析过程)-创新互联
此博客解决了什么问题:

解决测试的时候代码冗余的问题,解决了测试工程师的编码能力可能没有开发工程师编码能力的问题,解决了junit单元测试和spring注解相结合!
测试类代码:(只给大家展示测试类的代码)
public class AccountServiceTest {
@Test
public void testFindAll(){
//1.获取容器
ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml");
//2.得到业务层对象
IAccountService as =ac.getBean("accountService",IAccountService.class);
//3.执行方法
List accounts=as.findAllAccount();
for(Account account:accounts){
System.out.println(account);
}
}
@Test
public void testFindSave(){
Account account=new Account();
account.setMoney(20000f);
account.setName("test");
//1.获取容器
ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml");
//2.得到业务层对象
IAccountService as =ac.getBean("accountService",IAccountService.class);
as.saveAccount(account);
}
@Test
public void testFindUpdate(){
Account account=new Account();
//1.获取容器
ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml");
//2.得到业务层对象
IAccountService as =ac.getBean("accountService",IAccountService.class);
account=as.findAccountById(4);
account.setMoney(40000f);
as.updateAccount(account);
}
}
文章名称:javaspring整合junit操作(有详细的分析过程)-创新互联
文章起源:http://www.jxjierui.cn/article/hcphi.html


咨询
建站咨询
