<?xml version="1.0" encoding="UTF-8"?>
<project name="cobertura.examples.basic" default="coverage" basedir=".">
<description>
Cobertura - http://cobertura.sourceforge.net/
Copyright (C) 2003 jcoverage ltd.
Copyright (C) 2005 Mark Doliner <thekingant@users.sourceforge.net>
Cobertura is licensed under the GNU General Public License
Cobertura comes with ABSOLUTELY NO WARRANTY
</description>
<property name="build.dir" value="${basedir}/build"/>
<!-- 需要测试的代码生成的代码路径-->
<property name="classes.dir" value="${build.dir}/classes"/>
<!-- 为需要测试的代码生成的对应的测量类,用于测量覆盖率-->
<property name="instrumented.dir" value="${build.dir}/instrumented-classes"/>
<!-- 单元测试的代码,这部分代码不生成覆盖率数据,因此和待测试代码要分开-->
<property name="test.classes.dir" value="${build.dir}/test-classes"/>
<!-- 所有报告的路径-->
<property name="reports.dir" value="${build.dir}/reports"/>
<!-- junit 生成两种测试报告的路径,xml和html-->
<property name="reports.xml.dir" value="${reports.dir}/junit-xml"/>
<property name="reports.html.dir" value="${reports.dir}/junit-html"/>
<!-- cobertura生成的两种测试覆盖吕的报告,xml和html-->
<property name="coverage.xml.dir" value="${reports.dir}/cobertura-xml"/>
<property name="coverage.html.dir" value="${reports.dir}/cobertura-html"/>
<property name="src.dir" value="${basedir}/src" />
<!--测试代码的路径-->
<property name="test.dir" value="${basedir}/test" />
<path id="cobertura.classpath">
<fileset dir="${basedir}">
<include name="lib/unittest/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.classpath" resource="tasks.properties"/>
<target name="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${classes.dir}" />
<mkdir dir="${test.classes.dir}" />
<mkdir dir="${instrumented.dir}" />
<mkdir dir="${reports.xml.dir}" />
<mkdir dir="${reports.html.dir}" />
<mkdir dir="${coverage.xml.dir}" />
<mkdir dir="${coverage.html.dir}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src.dir}" destdir="${classes.dir}" debug="yes">
<classpath refid="cobertura.classpath" />
</javac>
</target>
<target name="compiletest" depends="compile">
<javac srcdir="${test.dir}" destdir="${test.classes.dir}" debug="yes">
<classpath location="${classes.dir}"/>
<classpath refid="cobertura.classpath" />
</javac>
</target>
<target name="instrument" depends="init,compile">
<!--
Remove the coverage data file and any old instrumentation.
-->
<delete file="cobertura.ser"/>
<delete dir="${instrumented.dir}" />
<!--
Instrument the application classes, writing the
instrumented classes into ${build.instrumented.dir}.
-->
<cobertura-instrument todir="${instrumented.dir}">
<!--
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="${classes.dir}">
<!--
Instrument all the application classes, but
don't instrument the test classes.
-->
<include name="**/*.class" />
<exclude name="**/*Test.class" />
</fileset>
</cobertura-instrument>
</target>
<target name="test" depends="init,compiletest">
<junit fork="yes" dir="${basedir}" haltonerror="no" failureProperty="test.failed">
<!--
Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important.
-->
<classpath location="${instrumented.dir}" />
<classpath location="${classes.dir}" />
<classpath location="${test.classes.dir}" />
<!--
The instrumented classes reference classes used by the
Cobertura runtime, so Cobertura and its dependencies
must be on your classpath.
-->
<classpath refid="cobertura.classpath" />
<formatter type="xml" />
<test name="${testcase}" todir="${reports.xml.dir}" if="testcase" />
<batchtest todir="${reports.xml.dir}" unless="testcase">
<fileset dir="${test.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
<junitreport >
<fileset dir="${reports.xml.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${reports.html.dir}" />
</junitreport>
</target>
<target name="coverage-check">
<cobertura-check branchrate="34" totallinerate="100" />
</target>
<target name="coverage-report">
<!--
Generate an XML file containing the coverage data using
the "srcdir" attribute.
-->
<cobertura-report srcdir="${src.dir}" destdir="${coverage.xml.dir}" format="xml" />
</target>
<target name="alternate-coverage-report">
<!--
Generate a series of HTML files containing the coverage
data in a user-readable form using nested source filesets.
-->
<cobertura-report destdir="${coverage.html.dir}">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
</cobertura-report>
</target>
<target name="clean" description="Remove all files created by the build/test process.">
<delete dir="${build.dir}" />
<delete dir="${classes.dir}" />
<delete dir="${instrumented.dir}" />
<delete dir="${reports.dir}" />
<delete file="cobertura.log" />
<delete file="cobertura.ser" />
</target>
<target name="coverage" depends="clean,compile,instrument,test,coverage-report,alternate-coverage-report" description="Compile, instrument ourself, run the tests and generate JUnit and coverage reports."/>
</project>
文章来源:
http://stocknewbie.bokee.com/viewdiary.15201790.html
posted on 2009-05-01 10:52
huohuo 阅读(667)
评论(0) 编辑 收藏