JUnit测试工具在项目中的用法

0:33 2013/6/26

三大框架整合时为什么要对项目进行junit测试:
    |__目的是测试配置文件对不对,能跑通就可以进行开发了

具体测试步骤:
    |__1.对hibernate进行测试 配置hibernate.cfg.xml
        public class TestHibernate {
               @Test
               public void save(){
        Configuration configuration = new Configuration();
        //加载类路径下的hibernate.cfg.xml
        configuration.configure();
        SessionFactory sf = configuration.buildSessionFactory();
        Session s = sf.openSession();
        Transaction tr = s.beginTransaction();
        //操作对象,就是操作表的过程
        ElecText elecText = new ElecText();
        elecText.setTextName("测试Hibernate名称");
        elecText.setTextDate(new Date());
        elecText.setTextRemark("测试Hibernate备注");
        s.save(elecText);
        tr.commit();
        s.close();
                }
        }
    |__2.对dao进行测试  测试之前确保beans.xml文件已配置,数据源可以暂时先不引不用开Tomcat不需要jsp进行显示
        public class TestDao {
               /**保存*/
               @Test
               public void save(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        IElecTextDao elecTextDao = (IElecTextDao) ac.getBean(IElecTextDao.SERVICE_NAME);
        ElecText elecText = new ElecText();
        elecText.setTextName("测试Dao名称");
        elecText.setTextDate(new Date());
        elecText.setTextRemark("测试DAO备注");
        elecTextDao.save(elecText);
                } 
                      }
    |__3.对service进行测试  测试之前确保beans.xml文件已配置,数据源可以暂时先不引不要开Tomcat不需要jsp进行显示
        public class TestService {
               @Test
               public void saveElecText(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        IElecTextService elecTextService = (IElecTextService) ac.getBean(IElecTextService.SERVICE_NAME);
        ElecText elecText = new ElecText();
        elecText.setTextName("测试Service名称");
        elecText.setTextDate(new Date());
        elecText.setTextRemark("测试Service备注");
        elecTextService.saveElecText(elecText);
               }
          }
    |__4.对二级缓存进行测试  配置hibernate.cfg.xml
        public class TestHibernateCache {
               /**测试类级别的缓存*/
               @Test
               public void classCache(){
        Configuration configuration = new Configuration();
        //加载类路径下的hibernate.cfg.xml
        configuration.configure();
        SessionFactory sf = configuration.buildSessionFactory();
        /***************************************************************/
        
        Session s = sf.openSession();
        Transaction tr = s.beginTransaction();
        
        ElecSystemDDL e1 = (ElecSystemDDL) s.get(ElecSystemDDL.class, 1);//产生select语句
        ElecSystemDDL e2 = (ElecSystemDDL) s.get(ElecSystemDDL.class, 1);//不产生select语句,从一级缓存中读取
        
        tr.commit();
        s.close();//一级缓存关闭了
        
        /********************************************************************/
        s = sf.openSession();
        tr = s.beginTransaction();
        
        ElecSystemDDL e3 = (ElecSystemDDL) s.get(ElecSystemDDL.class, 1);//不产生select语句,从二级缓存中读取
        
        tr.commit();
        s.close();
               }    
         }
    |__5.对jbpm进行测试  测试之前确保beans.xml文件已配置,数据源可以暂时先不引不要开Tomcat不需要jsp进行显示
        public class TestJbpm {
              /**生成JBPM的18张表*/
              @Test
              public void createTable_18(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        SessionFactory sf =  (SessionFactory) ac.getBean("sessionFactory");
        System.out.println("sf:"+sf);
               }
    
              /**测试流程引擎对象*/
              @Test
              public void testProcessEngine(){
        ApplicationContext ac = new ClassPathXmlApplicationContext("beans.xml");
        ProcessEngine processEngine = (ProcessEngine) ac.getBean("processEngine");
        System.out.println("processEngine:"+processEngine);
               }
                     }

        

 

转载于:https://www.cnblogs.com/YingYue/p/3742038.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值