- 浏览: 940351 次
- 性别:
- 来自: 江西上饶
文章分类
- 全部博客 (460)
- p.spring (56)
- p.maven (20)
- p.ant (17)
- p.jee (18)
- p.jse (33)
- p.ofbiz (31)
- p.软件工程 (8)
- p.struts2 (5)
- p.hibernate (5)
- linux (25)
- 设计模式 (2)
- p.javascript (11)
- 硬件 (1)
- p.jsp (2)
- p.windows批处理 (1)
- 操作系统问题 (5)
- 算法 (1)
- p.mysql (7)
- p.sql (5)
- p.c (1)
- google产品 (0)
- 内存 (1)
- p.struts (1)
- p.freemarker (7)
- p.css (4)
- p.log4j (10)
- p.html (3)
- 淘宝产品 (0)
- 其他 (3)
- 编译器 (0)
- svn (4)
- p.spring.security (11)
- 图形 (0)
- p.xml (1)
- p.ssh (0)
- p.jquery (4)
- p.jdbc (3)
- p.flex (0)
- p.c++ (0)
- p.c#Net (0)
- p.assembly (0)
- p.sqlserver (0)
- p.其他 (3)
- p.webwork (21)
- p.wap (12)
- p.cglib (1)
- p.jee服务器 (11)
- windows (2)
- p.iphone (1)
- p.java.分布式与集群 (2)
- p.ibatis (16)
- p.eclipse (5)
- 架构 (2)
- http协议 (5)
- 我的个人标准 (2)
- 多线程 (1)
- 奇怪问题 (5)
- p.jira (13)
- p.httpclient (1)
- 服务器.apache (11)
- 安全防范 (1)
- p.PODAM (1)
- p.junit (16)
- fop (2)
- 硬盘安装 (1)
- powerdesigner (0)
- 单元测试 (1)
- apache commons (4)
- tomcat+apache集群 (10)
- 各类诡辩 (1)
- 安卓 (8)
- qvod (1)
- java编程基础知识考试考点及答案 (0)
- 工作总结 (4)
- oracle (0)
- spring的util工具 (3)
- json (2)
- maven (3)
- jms (19)
- p.bat (3)
- hadoop (2)
- git (3)
- nginx (1)
- p.移动开发 (1)
- shiro (3)
- 游戏破解 (1)
- react-native (7)
- ios开发 (1)
- webmagic (6)
- socks5 (1)
最新评论
-
weituotian:
说的不好,没人看的
公司系统中的菜单功能和权限功能 -
石不易:
非常详细的注解~
绑定端口和IP,Listen 与VirtualHost指令 -
spring_springmvc:
spring mvc demo教程源代码下载,地址:http: ...
spring mvc -
liyixing1:
PandaDONG 写道谢谢你啊,我已经下下来了,只是还有很多 ...
jira war安装 -
liyixing1:
PandaDONG 写道谢谢你啊,我已经下下来了,只是还有很多 ...
jira war安装
cobertura原理大致如下:
首先修改我们编译后的class文件,再代码里面加入cobertura的统计代码。
然后运行我们的测试类,(那些统计代码会进行添加信息到ser文件)。
注意,Test类本身不能继承其他类,否则会报错。
cobertura下载
http://cobertura.sourceforge.net
下载解压
下载完成后添加
COBERTURA_HOME环境变量
以及设置path
例子
我的项目上如结构
第一步要做的是告诉cobertura去修改class文件
进入到项目目录
执行
E:\java\junit>cobertura-instrument --destination instrumented bin\test
会对bin\test下面的所有文件进行修改。修改后的文件放入instrumented目录(--destination参数指定存放修改后的class文件所在目录)
并生成ser文件。
E:\java\junit>java -cp lib\*;%COBERTURA_HOME%\cobertura.jar;instrumented;bin -Dne
t.sourceforge.cobertura.datafile=cobertura.ser org.junit.runner.JUnitCore test.C
alculatorTest
其中-Dne
t.sourceforge.cobertura.datafile=cobertura.ser指定测试信息写入到cobertura.ser档案文件。
生成报表
E:\java\junit>cobertura-report --format html --datafile cobertura.ser --destination reports src
--destination reports src指定报表文件存放在reports目录,源码文件从src中读取。
另外如果是使用utf-8编码的话,可能会出现如下错误
net.sourceforge.cobertura.javancss.parser.TokenMgrError: Lexical error at line 1
2, column 61. Encountered: "\r" (13), after : "\"\u7f01\u64b4\u7049\u6d93\u5d86
\ue11c\u7ead\ufffd, result,1, 0);"
at net.sourceforge.cobertura.javancss.parser.JavaParserTokenManager.getN
extToken(JavaParserTokenManager.java:2078)
at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_scan_token(Ja
vaParser.java:10181)
at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_3R_198(JavaPa
rser.java:8524)
这需要为文件指定默认编码。也就是加入-Dfile.encoding=utf-8 参数
修改cobertura-report.bat文件,更改
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-3.0.jar;%COBERTURA_HOME%lib\asm-tree-3.0.jar;%COBERTURA_HOME%lib\log4j-1.2.9.jar;%COBERTURA_HOME%lib\jakarta-oro-2.0.8.jar" net.sourceforge.cobertura.reporting.Main %CMD_LINE_ARGS%
为
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-
3.0.jar;%COBERTURA_HOME%lib\asm-tree-3.0.jar;%COBERTURA_HOME%
lib\log4j-1.2.9.jar;%COBERTURA_HOME%lib\jakarta-oro-2.0.8.jar" -
Dfile.encoding=utf-8 net.sourceforge.cobertura.reporting.Main %
CMD_LINE_ARGS%
成功后进入reports目录,打开index.html就能看到相关的测试信息。
ant
<?xml version="1.0" encoding="utf-8" ?>
<project name="superschool" default="all" basedir=".">
<property environment="env" />
<property name="projectName" value="superschool" />
<property name="src.dir" value="src/main/java" />
<property name="resource.dir" value="resource" />
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<property name="webroot.dir" value="WebContent" />
<property name="lib.dir" value="${webroot.dir}/WEB-INF/lib" />
<property name="lib.test.dir" value="test_lib" />
<property name="compiler.lib.dir" value="compiler_lib" />
<property name="target.dir" value="${build.dir}/target" />
<property name="target.app" value="${build.dir}/target/${projectName}" />
<property name="deploy.dir" value="${user.home}/${projectName}/webapp" />
<path id="class.path">
<pathelement location="${build.classes}" />
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${compiler.lib.dir}" includes="**/*.jar" />
<fileset dir="${lib.test.dir}" includes="**/*.jar">
</fileset>
</path>
<target name="clean" description="清理应用">
<description>
清理应用的build目录
</description>
<echo message="开始清理应用" />
<tstamp>
<format property="starttime_clean" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始时间:${starttime_clean}" />
<delete dir="${build.dir}" />
<delete dir="${deploy.dir}" />
<tstamp>
<format property="endtime_clean" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="应用清理完毕" />
<echo message="结束时间:${endtime_clean}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="compiler" description="编译项目">
<description>
编译项目
compiler.lib.dir特性指向的目录是存放编译需要的架包,
这个目录里面的架包是不会放到部署目录的lib目录的。
</description>
<tstamp>
<format property="starttime_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始编译" />
<echo message="开始时间:${starttime_compiler}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<!--编译源文件-->
<javac srcdir="${src.dir}" destdir="${build.classes}" debug="true" encoding="utf-8">
<classpath refid="class.path" />
</javac>
<!--拷贝配置文件-->
<copy todir="${build.classes}">
<fileset dir="${resource.dir}">
<exclude name="**/*.class" />
<exclude name="**/*.java" />
<exclude name="**/jdbc.properties" />
<exclude name="**/log4j.xml" />
</fileset>
</copy>
<property name="begintoken" value="$" />
<!--配置文件properties的antx功能-->
<copy encoding="utf-8" todir="${build.classes}/com/superschool/resource/spring/properties/jdbc">
<fileset dir="config">
<include name="jdbc.properties" />
</fileset>
<!--定义拷贝替换过滤器-->
<filterset begintoken="${begintoken}{" endtoken="}">
<filtersfile file="${user.home}/${projectName}/antx.properties" />
</filterset>
</copy>
<copy encoding="utf-8" todir="${build.classes}/com/superschool/resource/log4j">
<fileset dir="config">
<include name="log4j.xml" />
</fileset>
<filterset begintoken="${begintoken}{" endtoken="}">
<filtersfile file="${user.home}/${projectName}/antx.properties" />
</filterset>
</copy>
<tstamp>
<format property="endtime_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="编译成功结束" />
<echo message="结束时间:${endtime_compiler}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="make-app" description="生成项目文件夹">
<tstamp>
<format property="starttime_make-app" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成app" />
<echo message="开始时间:${starttime_make-app}" />
<mkdir dir="${target.app}" />
<mkdir dir="${target.app}/WEB-INF/lib" />
<mkdir dir="${target.app}/WEB-INF/classes" />
<!--拷贝app的WebContent目录到下面的文件到项目目录-->
<copy todir="${target.app}">
<fileset dir="${webroot.dir}" />
</copy>
<!--拷贝app的classes目录到下面的文件到项目目录的classes-->
<copy todir="${target.app}/WEB-INF/classes">
<fileset dir="${build.classes}">
<include name="**/**" />
</fileset>
</copy>
<!--拷贝app的lib目录到下面的文件到项目目录的lib-->
<copy todir="${target.app}/WEB-INF/lib">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</copy>
<tstamp>
<format property="endtime_make-app" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="app生成结束" />
<echo message="结束时间:${endtime_make-app}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="test" if="test">
<property name="cobertura.home" value="${env.COBERTURA_HOME}" />
<property name="src.test.dir" value="src/test/java" />
<property name="test.report.dir" value="${user.home}/${projectName}/test/report" />
<property name="test.report.html" value="${user.home}/${projectName}/test/report/html" />
<property name="cobertura.dir" value="${user.home}/${projectName}/test/cb" />
<path id="class.test.path">
<fileset dir="${lib.test.dir}" includes="**/*.jar">
</fileset>
</path>
<!--代码测试覆盖率配置class路径-->
<path id="class.cobertura.path">
<fileset dir="${cobertura.home}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<delete dir="${test.report.dir}" />
<delete dir="${test.report.html}" />
<delete file="${cobertura.dir}" />
<mkdir dir="${test.report.dir}" />
<mkdir dir="${test.report.html}" />
<mkdir dir="${cobertura.dir}" />
<!--代码覆盖率-->
<taskdef classpathref="class.cobertura.path" resource="tasks.properties" />
<tstamp>
<format property="starttime_test_cobertura" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试代码覆盖率" />
<echo message="开始时间:${starttime_test_cobertura}" />
<cobertura-instrument todir="${build.classes}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${build.classes}">
<include name="**/*.class" />
<exclude name="**/*Test*.class" />
</fileset>
</cobertura-instrument>
<tstamp>
<format property="endtime_test_cobertura" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="测试代码覆盖率生成结束" />
<echo message="结束时间:${endtime_test_cobertura}" />
<echo message="------------------------------" />
<echo message="" />
<!--编译测试类-->
<tstamp>
<format property="starttime_test_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始编译测试代码" />
<echo message="开始时间:${starttime_compiler}" />
<javac srcdir="${src.test.dir}" destdir="${build.classes}" debug="true" encoding="utf-8">
<classpath refid="class.path" />
<classpath refid="class.test.path" />
</javac>
<tstamp>
<format property="endtime_test_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="编译测试代码结束" />
<echo message="结束时间:${endtime_test_compiler}" />
<echo message="------------------------------" />
<echo message="" />
<!--运行测试-->
<tstamp>
<format property="starttime_test_run" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始运行测试代码" />
<echo message="开始时间:${starttime_test_run}" />
<!--此处必须让fork=yes,在一个新的vm中运行,否则,需要运行该build文件两次才能得到cobertura的html报表-->
<junit fork=yes printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="no">
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
<batchtest todir="${test.report.dir}">
<fileset dir="${src.test.dir}">
<include name="**/Test*.java" />
</fileset>
</batchtest>
<classpath refid="class.path" />
<classpath refid="class.test.path" />
<classpath refid="class.cobertura.path">
</classpath>
</junit>
<!--<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">
<formatter type="xml" />
<test name="s.A" todir="${test.report.dir}" />
<classpath refid="class.path" />
</junit>-->
<tstamp>
<format property="endtime_test_run" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="运行测试代码结束" />
<echo message="结束时间:${endtime_test_run}" />
<echo message="------------------------------" />
<echo message="" />
<!--生成报表-->
<tstamp>
<format property="starttime_test_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试报表" />
<echo message="开始时间:${starttime_test_html}" />
<mkdir dir="${test.report.html}" />
<junitreport todir="${test.report.dir}">
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.report.dir}/html" />
</junitreport>
<tstamp>
<format property="endtime_test_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="生成测试报表结束" />
<echo message="结束时间:${endtime_test_html}" />
<echo message="------------------------------" />
<echo message="" />
<tstamp>
<format property="starttime_cobertura_report_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试覆盖率报表" />
<echo message="开始时间:${starttime_cobertura_report_html}" />
<mkdir dir="${test.report.html}" />
<cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}" format="html" />
<!--删除报表主文件-->
<delete file="cobertura.ser">
</delete>
<tstamp>
<format property="endtime_cobertura_report_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="生成测试覆盖率报表结束" />
<echo message="结束时间:${endtime_cobertura_report_html}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="deploy" description="部署应用">
<tstamp>
<format property="starttime_deploy" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始部署" />
<echo message="开始时间:${starttime_deploy}" />
<delete dir="${deploy.dir}" />
<mkdir dir="${deploy.dir}" />
<copy todir="${deploy.dir}">
<fileset dir="${target.app}" />
</copy>
<echo message="部署结束" />
<tstamp>
<format property="endtime_deploy" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="结束时间:${endtime_deploy}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="all" description="所有操作" depends="clean, compiler, make-app, deploy, test">
<echo message="所有任务完成" />
</target>
</project>
首先修改我们编译后的class文件,再代码里面加入cobertura的统计代码。
然后运行我们的测试类,(那些统计代码会进行添加信息到ser文件)。
注意,Test类本身不能继承其他类,否则会报错。
cobertura下载
http://cobertura.sourceforge.net
下载解压
下载完成后添加
COBERTURA_HOME环境变量
以及设置path
例子
我的项目上如结构
第一步要做的是告诉cobertura去修改class文件
进入到项目目录
执行
E:\java\junit>cobertura-instrument --destination instrumented bin\test
会对bin\test下面的所有文件进行修改。修改后的文件放入instrumented目录(--destination参数指定存放修改后的class文件所在目录)
并生成ser文件。
E:\java\junit>java -cp lib\*;%COBERTURA_HOME%\cobertura.jar;instrumented;bin -Dne
t.sourceforge.cobertura.datafile=cobertura.ser org.junit.runner.JUnitCore test.C
alculatorTest
其中-Dne
t.sourceforge.cobertura.datafile=cobertura.ser指定测试信息写入到cobertura.ser档案文件。
生成报表
E:\java\junit>cobertura-report --format html --datafile cobertura.ser --destination reports src
--destination reports src指定报表文件存放在reports目录,源码文件从src中读取。
另外如果是使用utf-8编码的话,可能会出现如下错误
net.sourceforge.cobertura.javancss.parser.TokenMgrError: Lexical error at line 1
2, column 61. Encountered: "\r" (13), after : "\"\u7f01\u64b4\u7049\u6d93\u5d86
\ue11c\u7ead\ufffd, result,1, 0);"
at net.sourceforge.cobertura.javancss.parser.JavaParserTokenManager.getN
extToken(JavaParserTokenManager.java:2078)
at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_scan_token(Ja
vaParser.java:10181)
at net.sourceforge.cobertura.javancss.parser.JavaParser.jj_3R_198(JavaPa
rser.java:8524)
这需要为文件指定默认编码。也就是加入-Dfile.encoding=utf-8 参数
修改cobertura-report.bat文件,更改
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-3.0.jar;%COBERTURA_HOME%lib\asm-tree-3.0.jar;%COBERTURA_HOME%lib\log4j-1.2.9.jar;%COBERTURA_HOME%lib\jakarta-oro-2.0.8.jar" net.sourceforge.cobertura.reporting.Main %CMD_LINE_ARGS%
为
java -cp "%COBERTURA_HOME%cobertura.jar;%COBERTURA_HOME%lib\asm-
3.0.jar;%COBERTURA_HOME%lib\asm-tree-3.0.jar;%COBERTURA_HOME%
lib\log4j-1.2.9.jar;%COBERTURA_HOME%lib\jakarta-oro-2.0.8.jar" -
Dfile.encoding=utf-8 net.sourceforge.cobertura.reporting.Main %
CMD_LINE_ARGS%
成功后进入reports目录,打开index.html就能看到相关的测试信息。
ant
<?xml version="1.0" encoding="utf-8" ?>
<project name="superschool" default="all" basedir=".">
<property environment="env" />
<property name="projectName" value="superschool" />
<property name="src.dir" value="src/main/java" />
<property name="resource.dir" value="resource" />
<property name="build.dir" value="build" />
<property name="build.classes" value="${build.dir}/classes" />
<property name="webroot.dir" value="WebContent" />
<property name="lib.dir" value="${webroot.dir}/WEB-INF/lib" />
<property name="lib.test.dir" value="test_lib" />
<property name="compiler.lib.dir" value="compiler_lib" />
<property name="target.dir" value="${build.dir}/target" />
<property name="target.app" value="${build.dir}/target/${projectName}" />
<property name="deploy.dir" value="${user.home}/${projectName}/webapp" />
<path id="class.path">
<pathelement location="${build.classes}" />
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${compiler.lib.dir}" includes="**/*.jar" />
<fileset dir="${lib.test.dir}" includes="**/*.jar">
</fileset>
</path>
<target name="clean" description="清理应用">
<description>
清理应用的build目录
</description>
<echo message="开始清理应用" />
<tstamp>
<format property="starttime_clean" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始时间:${starttime_clean}" />
<delete dir="${build.dir}" />
<delete dir="${deploy.dir}" />
<tstamp>
<format property="endtime_clean" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="应用清理完毕" />
<echo message="结束时间:${endtime_clean}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="compiler" description="编译项目">
<description>
编译项目
compiler.lib.dir特性指向的目录是存放编译需要的架包,
这个目录里面的架包是不会放到部署目录的lib目录的。
</description>
<tstamp>
<format property="starttime_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始编译" />
<echo message="开始时间:${starttime_compiler}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<!--编译源文件-->
<javac srcdir="${src.dir}" destdir="${build.classes}" debug="true" encoding="utf-8">
<classpath refid="class.path" />
</javac>
<!--拷贝配置文件-->
<copy todir="${build.classes}">
<fileset dir="${resource.dir}">
<exclude name="**/*.class" />
<exclude name="**/*.java" />
<exclude name="**/jdbc.properties" />
<exclude name="**/log4j.xml" />
</fileset>
</copy>
<property name="begintoken" value="$" />
<!--配置文件properties的antx功能-->
<copy encoding="utf-8" todir="${build.classes}/com/superschool/resource/spring/properties/jdbc">
<fileset dir="config">
<include name="jdbc.properties" />
</fileset>
<!--定义拷贝替换过滤器-->
<filterset begintoken="${begintoken}{" endtoken="}">
<filtersfile file="${user.home}/${projectName}/antx.properties" />
</filterset>
</copy>
<copy encoding="utf-8" todir="${build.classes}/com/superschool/resource/log4j">
<fileset dir="config">
<include name="log4j.xml" />
</fileset>
<filterset begintoken="${begintoken}{" endtoken="}">
<filtersfile file="${user.home}/${projectName}/antx.properties" />
</filterset>
</copy>
<tstamp>
<format property="endtime_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="编译成功结束" />
<echo message="结束时间:${endtime_compiler}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="make-app" description="生成项目文件夹">
<tstamp>
<format property="starttime_make-app" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成app" />
<echo message="开始时间:${starttime_make-app}" />
<mkdir dir="${target.app}" />
<mkdir dir="${target.app}/WEB-INF/lib" />
<mkdir dir="${target.app}/WEB-INF/classes" />
<!--拷贝app的WebContent目录到下面的文件到项目目录-->
<copy todir="${target.app}">
<fileset dir="${webroot.dir}" />
</copy>
<!--拷贝app的classes目录到下面的文件到项目目录的classes-->
<copy todir="${target.app}/WEB-INF/classes">
<fileset dir="${build.classes}">
<include name="**/**" />
</fileset>
</copy>
<!--拷贝app的lib目录到下面的文件到项目目录的lib-->
<copy todir="${target.app}/WEB-INF/lib">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</copy>
<tstamp>
<format property="endtime_make-app" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="app生成结束" />
<echo message="结束时间:${endtime_make-app}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="test" if="test">
<property name="cobertura.home" value="${env.COBERTURA_HOME}" />
<property name="src.test.dir" value="src/test/java" />
<property name="test.report.dir" value="${user.home}/${projectName}/test/report" />
<property name="test.report.html" value="${user.home}/${projectName}/test/report/html" />
<property name="cobertura.dir" value="${user.home}/${projectName}/test/cb" />
<path id="class.test.path">
<fileset dir="${lib.test.dir}" includes="**/*.jar">
</fileset>
</path>
<!--代码测试覆盖率配置class路径-->
<path id="class.cobertura.path">
<fileset dir="${cobertura.home}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<delete dir="${test.report.dir}" />
<delete dir="${test.report.html}" />
<delete file="${cobertura.dir}" />
<mkdir dir="${test.report.dir}" />
<mkdir dir="${test.report.html}" />
<mkdir dir="${cobertura.dir}" />
<!--代码覆盖率-->
<taskdef classpathref="class.cobertura.path" resource="tasks.properties" />
<tstamp>
<format property="starttime_test_cobertura" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试代码覆盖率" />
<echo message="开始时间:${starttime_test_cobertura}" />
<cobertura-instrument todir="${build.classes}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${build.classes}">
<include name="**/*.class" />
<exclude name="**/*Test*.class" />
</fileset>
</cobertura-instrument>
<tstamp>
<format property="endtime_test_cobertura" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="测试代码覆盖率生成结束" />
<echo message="结束时间:${endtime_test_cobertura}" />
<echo message="------------------------------" />
<echo message="" />
<!--编译测试类-->
<tstamp>
<format property="starttime_test_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始编译测试代码" />
<echo message="开始时间:${starttime_compiler}" />
<javac srcdir="${src.test.dir}" destdir="${build.classes}" debug="true" encoding="utf-8">
<classpath refid="class.path" />
<classpath refid="class.test.path" />
</javac>
<tstamp>
<format property="endtime_test_compiler" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="编译测试代码结束" />
<echo message="结束时间:${endtime_test_compiler}" />
<echo message="------------------------------" />
<echo message="" />
<!--运行测试-->
<tstamp>
<format property="starttime_test_run" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始运行测试代码" />
<echo message="开始时间:${starttime_test_run}" />
<!--此处必须让fork=yes,在一个新的vm中运行,否则,需要运行该build文件两次才能得到cobertura的html报表-->
<junit fork=yes printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="no">
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
<batchtest todir="${test.report.dir}">
<fileset dir="${src.test.dir}">
<include name="**/Test*.java" />
</fileset>
</batchtest>
<classpath refid="class.path" />
<classpath refid="class.test.path" />
<classpath refid="class.cobertura.path">
</classpath>
</junit>
<!--<junit printsummary="yes" haltonerror="yes" haltonfailure="yes" fork="yes">
<formatter type="xml" />
<test name="s.A" todir="${test.report.dir}" />
<classpath refid="class.path" />
</junit>-->
<tstamp>
<format property="endtime_test_run" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="运行测试代码结束" />
<echo message="结束时间:${endtime_test_run}" />
<echo message="------------------------------" />
<echo message="" />
<!--生成报表-->
<tstamp>
<format property="starttime_test_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试报表" />
<echo message="开始时间:${starttime_test_html}" />
<mkdir dir="${test.report.html}" />
<junitreport todir="${test.report.dir}">
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.report.dir}/html" />
</junitreport>
<tstamp>
<format property="endtime_test_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="生成测试报表结束" />
<echo message="结束时间:${endtime_test_html}" />
<echo message="------------------------------" />
<echo message="" />
<tstamp>
<format property="starttime_cobertura_report_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始生成测试覆盖率报表" />
<echo message="开始时间:${starttime_cobertura_report_html}" />
<mkdir dir="${test.report.html}" />
<cobertura-report srcdir="${src.dir}" destdir="${cobertura.dir}" format="html" />
<!--删除报表主文件-->
<delete file="cobertura.ser">
</delete>
<tstamp>
<format property="endtime_cobertura_report_html" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="生成测试覆盖率报表结束" />
<echo message="结束时间:${endtime_cobertura_report_html}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="deploy" description="部署应用">
<tstamp>
<format property="starttime_deploy" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="开始部署" />
<echo message="开始时间:${starttime_deploy}" />
<delete dir="${deploy.dir}" />
<mkdir dir="${deploy.dir}" />
<copy todir="${deploy.dir}">
<fileset dir="${target.app}" />
</copy>
<echo message="部署结束" />
<tstamp>
<format property="endtime_deploy" pattern="yyyy-MM-dd HH:mm:ss" />
</tstamp>
<echo message="结束时间:${endtime_deploy}" />
<echo message="------------------------------" />
<echo message="" />
</target>
<target name="all" description="所有操作" depends="clean, compiler, make-app, deploy, test">
<echo message="所有任务完成" />
</target>
</project>
发表评论
-
运行swing等可视化程序
2014-03-26 14:55 841Ant中调用的时候,总是一闪而过。 需要添加 <java ... -
ant path匹配
2013-07-22 09:40 2136spring和ant path实现相关的主要类有两个 org. ... -
自定义任务
2012-11-21 22:33 1133<!-- 代码覆盖率任务定义,classpathref直 ... -
copy的时候,保持原有的目录结构
2012-11-21 17:31 1778flatten:用于指定是否需要复制目录,如果为true代表把 ... -
给ant指定内存
2012-02-14 12:40 1193Windows操作系统,在运行ant的bat脚本文件: set ... -
DEBUG -- CLOSE BY CLIENT STACK TRACE
2011-10-20 10:28 27594在单元测试测试环境下主要参数两个错误信息: 1.java.la ... -
奇怪的乱码
2011-10-20 00:14 1335通过ant运行build,然后启动测试。测试的时候有log4j ... -
junit - formatter 等等和测试有关的指令
2011-10-18 22:38 1283<formatter> </formatte ... -
mock对象测试
2011-10-17 22:48 1287package mock; public class Acc ... -
依赖外部资源时解决方案-----存根
2011-10-17 22:08 1438package stubbing; import java. ... -
文件移动或者复制的时候完成文件中的文本替换。实现antx功能
2011-10-15 11:56 2039filterset DataType ant1.4支持。定义 ... -
软件测试的种类
2011-09-18 17:58 1122acceptance test 验收测试 你的程序满足了客户的 ... -
hamcrest
2011-09-18 16:51 1174在一个测试用例中,有时候不得不存在多个断言,比如 @Test ... -
@Ignore 指定跳过测试用例
2011-09-18 16:06 1717在3.x版本中,如果我们不想启动某些测试,需要将方法名更改为非 ... -
@Test
2011-09-17 23:27 8070@Test注解是测试的基础,它提供了其他作用 1.指定将会抛 ... -
测试规范
2011-09-16 00:27 975测试方法名一般有两种 testxxxx xxxx是要测试的域 ... -
@Before, @BeforeClass, @After, @AfterClass
2011-09-15 23:30 7790@Before, @BeforeClass, @After, ... -
Suite runner
2011-09-14 23:29 1120套件运行器 它可以运行多个测试。 package test; ... -
@Parameters Parameterized runner
2011-09-14 22:46 1590先看一个例子 package te ... -
junit的核心对象
2011-09-12 21:52 1148概念责任Assert不同条件的断言。如果成功,无什么特殊的信息 ...
相关推荐
NULL 博文链接:https://mwhgjava.iteye.com/blog/1297276
NULL 博文链接:https://terrencexu.iteye.com/blog/718834
Junit+ant+cobertura示例源码程序。
Cobertura代码覆盖率测试工具介绍文档,Cobertura代码覆盖率测试工具介绍
Cobertura是一种开源工具,它通过检测基本的代码,并观察在测试包运行时执行了哪些代码和没有执行哪些代码,来测量测试覆盖率。除了找出未测试到的代码并发现bug外,Cobertura还可以通过标记无用的、执行不到的代码...
Cobertura是一个测试案例覆盖率统计工具,此资源下载后,解压,配置上环境变量即可使用
代码测试覆盖率工具,该工具与ant执行集成,快速简单有效的测试代码的覆盖率,内附测试用例
cobertura代码覆盖率工具,有工具包,并且付上一份自己给项目组写的手册一份。
Cobertura 是一种代码覆盖测试工具,它通过检测基本的代码,并观察在测试包运行时执行了哪些代码和没有执行哪些代码,来测量测试覆盖率。
示例build文件 博文链接:https://zhupan.iteye.com/blog/200878
cobertura 单元测试覆盖率
EMMA,它是一个免费、开源的、用来衡量单元测试覆盖度... EMMA生成的报告类似于Cobertura(另一个功能类似于EMMA的开源工具),请参考:用Ant+JUnit+Cobertura轻松控制单元测试质量:http://ouzhong.blog.hexun.com/323
cobertura和weblogic整合使用-代码覆盖率测试 里面详细步骤和使用说明,并附加xml文件,不懂的可以QQ我,147806015,
它也旨在通过pycobertura diff命令来防止代码覆盖率降低:任何更改的行都应进行测试,并且未覆盖的更改应清晰可见,而不会让遗留的未覆盖代码成为pycobertura diff因此开发人员可以仅专注于其更改。 特征: 显示...
cobertura测试代码
此包使用分析器生成 Cobertura 样式的 XML 覆盖率报告。 我们将此报告与 Hudson/Jenkins 结合使用来跟踪测试覆盖率。 下面的代码示例说明了如何使用代码。 有关详细信息,请参见 example.m。 %将源代码添加到路径...
代码测试覆盖率工具包cobertura.jar
cobertura1.9.1,里面有一个现成的ant+junit+cobertura的build.xml文件。