ssh 相关方面的测试

原来对测试不够重视,出现问题的时候,靠着开着服务器在哪调试,确实搞得很麻烦。。遇到问题想用junit 进行单元测试的时候,却发现忘了怎么来做了,真是悲哀!现在总结下,以后就不会发生这种事了。。

 

1、Hibernate 的语句测试

SessionFactory sf=new Configuration().configure().buildSessionFactory();
		Session session=sf.openSession();
		Query q=session.createQuery("from Article a where a.banner.banner.id=1");
		List l=q.list();

 

configure()方法默认会在classpath下面寻找hibernate.cfg.xml或者hibernate.properties文件。如果名字不同的话,则用Configuration cfg = new Configuration().configure("myexample.xml");

 

2、Spring 测试

public abstract class SpringTestCaseBase extends AbstractTransactionalDataSourceSpringContextTests { 
protected SimpleDateFormat sdf; 

public SpringTestCaseBase() { 
// query the protected variables to implement denpendency injection automatically, 
// so we don't need to write settor and gettor methods anymore. 
this.setPopulateProtectedVariables(true); 

sdf = new SimpleDateFormat("yyyy-MM-dd"); 
sdf.setTimeZone(TimeZone.getDefault()); 
} 

protected String[] getConfigLocations() { 
return new String[] { "file:web/WEB-INF/applicationContext*.xml", 
          "file:web/WEB-INF/test-ApplicationContext*.xml"}; 
    } 

protected void flushSession(){ 
SessionFactory sessionFactory = (SessionFactory)applicationContext.getBean("sessionFactory");   
        sessionFactory.getCurrentSession().flush(); 
    } 
} 

 

 

有空继续更新!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值