频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

在eclipse中使用Ant执行JUnit

来源: 作者:cerulean 出处:巧巧读书 2008-02-12 进入讨论组

建立工程:

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 </ project >
运行:
右键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,异常的详细信息也会输出在这里.

   巧巧读书:http://www.qqread.com/java/2008/02/e396810.html

更多文章 更多内容请看Eclipse应用技术专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章