qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          在SSH中增加JUNIT4單元測試

            首先,需要將UNITILS相關的jar包導入到系統的依賴jar包文件lib中,相關的jar文件如下:
          dbunit-2.4.8.jar
          hamcrest-all-1.3.0RC2.jar
          hamcrest-library-1.1.jar
          htmlunit-2.8.jar
          htmlunit-core-js-2.8.jar
          httpclient-4.0.2.jar
          httpcore-4.0.1.jar
          httpmime-4.0.1.jar
          junit-4.8.2.jar
          mockito-all-1.8.5.jar
          nekohtml-1.9.14.jar
          operadriver-v0.6.jar
          selaid-1.0.1.jar
          selenium-java-2.4.0.jar
          spring-ws-test-0.22.jar
          testng-5.14.4.jar
          unitils-core-3.1.jar
          unitils-database-3.1.jar
          unitils-dbmaintainer-3.1.jar
          unitils-dbunit-3.1.jar
          unitils-mock-3.1.jar
          unitils-orm-3.1.jar
          unitils-spring-3.1.jar
          unitils-testng-3.1.jar
          xmlunit-1.2.jar
          xmlunit-1.3.jar
            此外,除了常見的jar包之外,還有一個commons-lang包也是需要的,具體報錯的時候,在網上找一下就ok了.
            然后,使用Eclipse的new功能,創建一個基于Junit4的test case,需要注意的事情是,需要讓該test case能夠得到spring 的SpringApplicationContext對象,得到了Spring的SpringApplicationContext對象之后,后面的測試用例就比較簡單了.在獲取SpringApplicationContext的時候,一定要注意注解里面的文件位置的獲取.我們可以多看一下編譯之后的文件,不要僅僅依據eclipse的文件的位置來判斷相對位置.下面是我的Test Case的父類,以及子測試類:
          package com.ziwen.common;
          import org.springframework.context.ApplicationContext;
          import org.unitils.UnitilsJUnit4;
          import org.unitils.spring.annotation.SpringApplicationContext;
          public class CommonTest extends UnitilsJUnit4{
          @SpringApplicationContext({
          "springConfig/applicationContext.xml",
          "springConfig/bizContext.xml",
          "springConfig/daoContext.xml"})
          private ApplicationContext applicationContext;
          public ApplicationContext getApplicationContext() {
          return applicationContext;
          }
          public void setApplicationContext(ApplicationContext applicationContext) {
          this.applicationContext = applicationContext;
          }
          }
          子類:
          package com.ziwen.biz;
          import static org.junit.Assert.assertNotNull;
          public class TestDemoBiz extends CommonTest{
          @SpringBean("demoBiz")
          private DemoBiz demobiz;
          @Test
          public void testDoSth() {
          List<Demo> list=demobiz.getDemoList(new Page(10));
          assertTrue(list.size()>1);
          }
          @Test
          public void testGetDemoList() {
          String str=demobiz.doSth();
          assertNotNull(str);
          }
          }


           測試的結果:

          posted on 2013-09-25 11:33 順其自然EVO 閱讀(335) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年9月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 呼玛县| 昌乐县| 山西省| 镇平县| 甘孜县| 铜陵市| 阳曲县| 紫金县| 滦平县| 常熟市| 永修县| 苍梧县| 工布江达县| 普陀区| 海伦市| 双桥区| 方城县| 秭归县| 乐清市| 故城县| 伊春市| 宜兰市| 淳化县| 龙山县| 阜新市| 扎囊县| 南乐县| 太湖县| 陕西省| 垦利县| 叶城县| 洪泽县| 高邑县| 上杭县| 镇康县| 湘西| 泽州县| 当阳市| 涪陵区| 永登县| 台湾省|