cerulean

          在eclipse中使用Ant執行JUnit

          建立工程:
          在eclipse中建立一個java project.
          AntTest
          ?-src
          ??-com.test
          ???-ABS.java
          ???-ABSTest.java (Junit Test Case)
          ?-lib
          ?-build.xml
          ?-JUNIT_HOME/junit.jar

          配置:
          eclipse->window->preference->ANT->Runtime->Classpath->ANT Home Entry
          選擇Add External JAR,加入ECLIPSE_HOME/plugins/org.junit.../junit.jar

          build.xml的內容:

          ?1
          ?2 <? xml?version="1.0" ?>
          ?3 < project? name ="project" ?default ="junit" >
          ?4 ? < property? name ="run.classpath" ?value ="bin" ></ property >
          ?5 ? < property? name ="run.srcpath" ?value ="src" ></ property >
          ?6 ? < property? name ="test.srcpath" ?value ="src" ></ property >
          ?7 ? < property? name ="test.report" ?value ="report" ></ property >
          ?8 ? < property? name ="lib.dir" ?value ="lib" ? />
          ?9 ? < path? id ="compile.path" >
          10 ?? < fileset? dir ="${lib.dir}" >
          11 ??? < include? name ="**/*.jar" ? />
          12 ?? </ fileset >
          13 ? </ path >
          14 ? < target? name ="compile" >
          15 ?? < javac? destdir ="${run.classpath}" ?srcdir ="${run.srcpath}" ?classpathref ="compile.path" ? />
          16 ?? < javac? destdir ="${run.classpath}" ?srcdir ="${test.srcpath}" ?classpathref ="compile.path" ? />
          17 ? </ target >
          18 ? < target? name ="junit" ?depends ="compile" >
          19 ?? < tstamp? />
          20 ?? < mkdir? dir ="${test.report}" ? />
          21 ?? < mkdir? dir ="${test.report}/framework-${DSTAMP}-${TSTAMP}" ? />
          22 ?? < junit? printsummary ="true" >
          23 ??? < classpath >
          24 ???? < pathelement? path ="${run.classpath}" ? />
          25 ???? < fileset? dir ="${lib.dir}" >
          26 ????? < include? name ="**/*.jar" ? />
          27 ???? </ fileset >
          28 ??? </ classpath >
          29 ??? < formatter? type ="plain" ? />
          30 ??? < batchtest? fork ="yes" ?todir ="${test.report}/framework-${DSTAMP}-${TSTAMP}" >
          31 ???? < fileset? dir ="${test.srcpath}" >
          32 ????? < include? name ="**/*Test.java" ? />
          33 ???? </ fileset >
          34 ??? </ batchtest >
          35 ?? </ junit >
          36 ? </ target >
          37
          38 </ project >
          39
          40



          運行:
          右鍵build.xml->run as "Ant Build".

          結果:
          控制臺有輸出結果,例如:
          Buildfile: C:\Documents and Settings\qianwang\My Documents\D\SMPWorkspace\AntTest\build.xml
          compile:
          junit:
          ??? [mkdir] Created dir: C:\Documents and Settings\qianwang\My Documents\D\SMPWorkspace\AntTest\report\framework-20070201-1712
          ??? [junit] Running com.test.ABSTest
          ??? [junit] Tests run: 3, Failures: 0, Errors: 0, Time elapsed: 0 sec
          BUILD SUCCESSFUL
          Total time: 19 seconds

          同時,AntTest/report(如果沒有自動建立的目錄)中,產生.txt格式的文本文件.
          結果文件中,會指出運行了哪些testcase(指出被測試的方法名test**).
          如果有failures/errors,異常的詳細信息也會輸出在這里.

          posted on 2007-02-08 21:17 cerulean 閱讀(2523) 評論(0)  編輯  收藏 所屬分類: eclipseAnt

          導航

          <2007年2月>
          28293031123
          45678910
          11121314151617
          18192021222324
          25262728123
          45678910

          統計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 宝清县| 舒城县| 枣庄市| 湘潭市| 湟中县| 南澳县| 客服| 罗山县| 海林市| 石狮市| 建阳市| 仙桃市| 望谟县| 唐山市| 兴化市| 婺源县| 莱阳市| 寿光市| 肇州县| 武安市| 都兰县| 万宁市| 汝南县| 交口县| 留坝县| 安庆市| 英吉沙县| 罗定市| 浑源县| 桐梓县| 宝坻区| 合江县| 康乐县| 界首市| 咸宁市| 甘谷县| 乌兰浩特市| 余姚市| 京山县| 澄迈县| 清丰县|