waterye

          Hibernate Test Case

          習慣Spring + Hibernate帶來的方便, 但有時在應用中測試Hibernate的新功能并不是很方便.
          實際上Hibernate的test代碼就有這個功能, 而且不用考慮create table等麻煩事.

          在自己的project中使用, 只需繼承org.hibernate.test.TestCase, 改變hand code的路徑, 設定hibernate.properties文件, 這樣就有了純Hibernate測試環境
          public abstract class HibernateTestCase extends TestCase
          {
              
          protected HibernateTestCase(String x)
              
          {
                  super(x);
              }


              
          protected String getBaseForMappings() {
                  
          return "com/waterye/test/";
              }


              
          /**
               * true時, 使用auto schema export, hibernate.hbm2ddl.auto create-drop
               
          */

              
          protected boolean recreateSchema() {
                  
          return false;
              }

          }


          說明:  以idea為例
          1. 將hibernate.properties放到test根目錄下
          2. pojo, hbm.xml, Test.java放到同一目錄下(參考hibernate的測試代碼)
          3. 在idea中run test method

          posted on 2005-08-20 21:33 waterye 閱讀(1200) 評論(1)  編輯  收藏 所屬分類: hibernate

          Feedback

          # re: Hibernate Test Case 2005-08-25 21:41 江南白衣@ITO

          在testcase中,自動根據hbm創建數據表這功能比較BT....寫Demo型的測試用例根本不需要再帶一個DDL文件,更不用帶N個不同數據庫的DDL文件。  回復  更多評論   

          主站蜘蛛池模板: 新干县| 西昌市| 江孜县| 华坪县| 荔波县| 连城县| 西贡区| 大余县| 鹤峰县| 萨嘎县| 宁安市| 岢岚县| 涞源县| 镇赉县| 米泉市| 炉霍县| 天峨县| 福建省| 绥中县| 额敏县| 罗田县| 天津市| 吕梁市| 通江县| 蒙阴县| 精河县| 襄城县| 安多县| 杨浦区| 江达县| 忻州市| 安陆市| 镇坪县| 五大连池市| 永仁县| 拉萨市| 瓮安县| 蒲城县| 临泽县| 丹凤县| 普格县|