下面的那一大段build.xml文件内容主要也是参考下载过来的JCoverage中的一个例子中的build文件,只是稍稍作了点修改,用下面这个build文件前,需要把JCoverage用到的 jar (下载的JCoverage中都有) 包拷到工程目录下lib子目录中,请注意理解其中的注解,以后必要时会加上更详细的中文注释。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
<?xml version="1.0" encoding="gb2312"?> <project name="jcoverage.examples" default="main" basedir="."> <!-- all build artefacts are deposited under this directory. --> <property name="build.dir" value="${basedir}/build"/> <!-- classes generated by the javac compiler are deposited in this directory. --> <property name="build.classes.dir" value="${build.dir}/classes"/> <!-- instrumented classes are deposited into this directory. --> <property name="build.instrumented.dir" value="${build.dir}/instrumented-classes"/> <!-- coverage reports are deposited into this directory. For the HTML report, look at ${build.coverage.dir}/index.html. For the XML report look at ${build.coverage.dir}/coverage.xml. --> <property name="build.coverage.dir" value="${build.dir}/coverage"/> <!-- unit test reports from junit are deposited in this directory. --> <property name="build.reports.dir" value="${build.dir}/reports"/> <!-- third party libraries that are also shipped with jcoverage can be found in this directory. JCoverageLib directory contains bcel.jar, jakarta-oro-2.0.7.jar java-getopt-1.0.9.jar, jcoverage.jar, junit,log4j-1.2.8.jar --> <property name="jcoverage.lib.dir" value="${basedir}/JCoverageLib"/> <!-- the source code for the examples can be found in this directory. --> <property name="src.dir" value="${basedir}/src"/> <target name="main" depends="clean,init,compile,instrument,test,coverage" description="clean build, instrument and unit test"/> <!-- libraries path, can define a universal classpath as below <path id="junit"> <fileset dir="${lib.dir}"> <include name="junit/3.8.1/*.jar"/> </fileset> </path> <path id="log4j"> <fileset dir="${lib.dir}"> <include name="log4j/1.2.8/*.jar"/> </fileset> </path> <path id="jcoverage"> <fileset dir="${dist.dir}"> <include name="jcoverage.jar"/> </fileset> </path> --> <!-- define class path for all the library needed --> <path id="jcoverage.class.path"> <fileset dir="${jcoverage.lib.dir}"> <include name="*.jar"/> </fileset> </path> <!-- 现在还不知道resource指定的tasks.properties(不存在)是做什么用的 --> <taskdef classpathref="jcoverage.class.path" resource="tasks.properties"/> <target name="clean" description="clean up build artefacts"> <delete quiet="true"> <fileset dir="${build.dir}"/> <fileset dir="${basedir}"> <include name="jcoverage.ser"/> <include name="jcoverage.log"/> </fileset> </delete> </target> <target name="init" description="create build directories"> <mkdir dir="${build.dir}"/> <mkdir dir="${build.classes.dir}"/> <mkdir dir="${build.coverage.dir}"/> <mkdir dir="${build.instrumented.dir}"/> <mkdir dir="${build.reports.dir}"/> </target> <target name="compile" description="compile all classes"> <javac srcdir="${src.dir}" destdir="${build.classes.di*}" **ilonerror="yes" debug="yes"> <!-- <classpath refid="junit"/> <classpath refid="log4j"/> --> <classpath refid="jcoverage.class.path"/> </javac> </target> <target name="instrument" description="Add jcoverage instrumentation"> <!-- instrument the application classes, writing the instrumented classes into ${build.instrumented.dir}. --> <instrument todir="${build.instrumented.dir}"> <!-- Note that the following line causes instrument to ignore any source line containing a reference to log4j, for the purposes of coverage reporting. --> <ignore regex="org.apache.log4j.*"/> <fileset dir="${build.classes.dir}"> <!-- instrument all the application classes, but don't instrument the test classes. --> <include name="**/*.clas*"/> <**clude name="**/*Test.class"/> </fileset> </instrument> </target> <target name="test" description="Unit test the application"> <junit fork="yes" dir="${basedir}" errorProperty="test.failed" failureProperty="test.failed"> <!-- note the classpath order, instrumented classes are before the original (uninstrumented) classes. --> <classpath location="${build.instrumented.dir}"/> <classpath location="${build.classes.dir}"/> <!-- the instrumented classes reference classes used by the jcoverage runtime. --> <!-- <classpath refid="jcoverage"/> --> <classpath refid="jcoverage.class.path"/> <formatter type="xml"/> <batchtest todir="${build.reports.dir}"> <fileset dir="${src.dir}"> <include name="**/*Test.java"/> </fileset> </batchtest> </junit> </target> <target name="coverage" description="HTML and XML coverage reports can be found in build/coverage"> <report srcdir="${src.dir}" destdir="${build.coverage.dir}"/> <report srcdir="${src.dir}" destdir="${build.coverage.dir}" format="xml"/> </target> </project> |
下面也许有必要粘贴一些用JCoverage生成的覆盖率报告界面图来。
本文链接 https://yanbin.blog/jcoverage-report-build-file/, 来自 隔叶黄莺 Yanbin Blog
[版权声明] 本文采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 进行许可。