- 关键Ant的build文件如下(已加上比较详细的说明)下面以后也会加上测试报告的贴图的。
1<?xml version="1.0" encoding="UTF-8"?> 2<project basedir="." default="main" name="excute TestCase and build test report"> 3 <!-- 测试报告存放目录 --> 4 <property name="build.reports.dir" value="${basedir}/report" /> 5 <target name="main"> 6 <!-- 删除测试报告数据,重新生成 --> 7 <delete> 8 <fileset dir="${basedir}/report"> 9 <include name="*.*" /> 10 </fileset> 11 </delete> 12 <junit fork="yes" printsummary="true"> 13 <!-- 生成的class目录以及执行TestCase所依赖的库 14 无论是用<test>还是<batchtest>都要这个配置 --> 15 <classpath location="${basedir}/bin" /> 16 <!-- 生成报告数据的格式,可能多个,支持xml/brief/plain --> 17 <formatter type="xml" /> 18 <formatter type="brief" usefile="false" /> 19 <!-- 可以用<test>也可以用<batchtest>,但两种的设置有一些区别 20 以下<test>和<batchtest>三种形式用某一种就可以的 --> 21 <!-- name指定Class的名称,如CatTest或com.unmi.CatTest --> 22 <test name="CatTest" todir="${build.reports.dir}" /> 23 <!-- 注意其中<fileset>的dir属性及<include>的name属性指代的意义 --> 24 <batchtest todir="${build.reports.dir}"> 25 <!-- dir属性指定TestCase类的源代码的路径 --> 26 <fileset dir="${basedir}/src"> 27 <!-- name属性指定TestCase源文件规则 --> 28 <include name="**/*Test.java" /> 29 </fileset> 30 </batchtest> 31 <!-- 上面的<batchtest>还可以写成如下形式,<fileset>按指定为class 32 注意其中<fileset>的dir属性及<include>的name属性指代的意义 --> 33 <batchtest todir="${build.reports.dir}"> 34 <!-- dir属性指定TestCase类的路径 --> 35 <fileset dir="${basedir}/bin"> 36 <!-- name属性指定TestCase类文件规则 --> 37 <include name="**/*Test.class" /> 38 </fileset> 39 </batchtest> 40 </junit> 41 <!-- 用执行以上TestCase生成的报告数据生成测试报告 --> 42 <junitreport todir="${build.reports.dir}"> 43 <fileset dir="${build.reports.dir}"> 44 <include name="TEST-*.xml" /> 45 </fileset> 46 <!-- 指定生成测试报告的格式frames/noframes,和报告存放目录 --> 47 <report format="frames" todir="${build.reports.dir}" /> 48 </junitreport> 49 </target> 50</project> - 下面的那一大段build.xml文件内容主要也是参考下载过来的JCoverage中的一个例子中的build文件,只是稍稍作了点修改,用下面这个build文件前,需要把JCoverage用到的 jar (下载的JCoverage中都有) 包拷到工程目录下lib子目录中,请注意理解其中的注解,以后必要时会加上更详细的中文注释。 Read More
- JCoverage不是免费的(对商业不是免费,对open source是免费的
JCoverage主页:http://www.jcoverage.com
JCoverage的允许需要JUnit和Log4j、bcel、jakarta-oro、getopt类库,这些类库在下载的JCoverage中都包含了,JCoverage主要也是和Ant结合在一起使用,
注意事项:
1 : 初始化是最好删除当前目录下的jcoverage.ser文件,这个文件就是测试的结果,如果其在当前目录下找到这个文件将不会进行测试,或者重新测试
2 : 在进行instrument时,一定要保证其class是debug模式下编译的,否则将不能注入jcoverage指令到被测试类的二进制文件中,建议从新用debug模式编译一个在当前目录 Read More
现在我们安装Linux的时候通常考虑到安全因素(默认情况下)是不打开telnet服务的,而ssh服务是有的,ant很早就支持telnet,但要求我们在Linux下要安装telnet-server,并要启用该服务。
还好自Ant1.60开始支持了SSH 及SCP 操作了,早在Ant之前若要支持SSH、SCP、SFTP等任务就必须下载j2ssh的j2ssh-ant.jar和j2ssh-core.jar(在http://www.sourceforge.net的j2ssh下有下载)。现在可以使用Ant提供的Sshexec和scp任务,由$ANT_HOME/lib/ant-jsch.jar提供支持,但是同样你也要在http://www.jcraft.com/jsch/index.html下载一个依赖包jsch-0.1.24.jar(文件名因版本而不同),jsch同样也是http://www.sourceforge.net下的一个项目。
你需要把下载的jsch-0.1.24拷贝到$ANT_HOME/lib下,如果是Eclipse下的Ant环境必须在Window->Preferences->Ant->Runtime->Classpath中加入jsch-0.1.24。 Read More