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 閱讀(337) 評論(0)  編輯  收藏


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


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

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 达日县| 会宁县| 金坛市| 临安市| 绥芬河市| 惠水县| 讷河市| 澄江县| 沂南县| 马尔康县| 泰兴市| 景宁| 武义县| 酒泉市| 明溪县| 井研县| 平安县| 报价| 北京市| 柳河县| 盐池县| 平定县| 务川| 凌云县| 安远县| 托克托县| 沐川县| 安平县| 化隆| 两当县| 保靖县| 肇州县| 同仁县| 依兰县| 贵港市| 张家界市| 玛纳斯县| 博爱县| 澄江县| 山阳县| 竹山县|