新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
javaspring整合junit操作(有詳細(xì)的分析過程)-創(chuàng)新互聯(lián)
此博客解決了什么問題:
解決測(cè)試的時(shí)候代碼冗余的問題,解決了測(cè)試工程師的編碼能力可能沒有開發(fā)工程師編碼能力的問題,解決了junit單元測(cè)試和spring注解相結(jié)合!
測(cè)試類代碼:(只給大家展示測(cè)試類的代碼)
public class AccountServiceTest { @Test public void testFindAll(){ //1.獲取容器 ApplicationContext ac=new ClassPathXmlApplicationContext("bean.xml"); //2.得到業(yè)務(wù)層對(duì)象 IAccountService as =ac.getBean("accountService",IAccountService.class); //3.執(zhí)行方法 Listaccounts=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.得到業(yè)務(wù)層對(duì)象 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.得到業(yè)務(wù)層對(duì)象 IAccountService as =ac.getBean("accountService",IAccountService.class); account=as.findAccountById(4); account.setMoney(40000f); as.updateAccount(account); } }
新聞標(biāo)題:javaspring整合junit操作(有詳細(xì)的分析過程)-創(chuàng)新互聯(lián)
分享路徑:http://www.ef60e0e.cn/article/hcphi.html