zoukankan      html  css  js  c++  java
  • 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);
                   }
                         }
    
            
  • 相关阅读:
    Android见招拆招十:Migrate Android Code
    Android转载三:(布局)ImageView中src与background的区别
    Android见招拆招九:字符编码问题导入项目报错
    Android见招拆招八:多次遇到的R.java编译问题
    Android学习笔记五:(布局)Layout_margin和Layout_padding的区别
    Android见招拆招七:Error parsing XML: no element
    Window10系统修改hosts文件的方法
    Foxmail:‘错误信息:由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败’的解决办法
    Oracle 查询NULL字段/空字符串
    Python 安装第三方模块时 报Retrying(Retry(total=4, connect=None, read=None, redirect=None, status=None))...[WinError 10061]由于目标计算机积极拒绝,无法连接 错误
  • 原文地址:https://www.cnblogs.com/YingYue/p/3742038.html
Copyright © 2011-2022 走看看