网站建设资讯

NEWS

网站建设资讯

javaspring整合junit操作(有详细的分析过程)-创新互联

此博客解决了什么问题:

成都创新互联公司成立于2013年,是专业互联网技术服务公司,拥有项目成都网站设计、成都网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元下陆做网站,已为上家服务,为下陆各地企业和个人服务,联系电话:18982081108

解决测试的时候代码冗余的问题,解决了测试工程师的编码能力可能没有开发工程师编码能力的问题,解决了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操作(有详细的分析过程)-创新互联
URL地址:http://cdweb.net/article/hcphi.html