隨筆-77  評論-5  文章-2  trackbacks-0

          <?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 &lt;thekingant@users.sourceforge.net&gt;
              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 閱讀(676) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 呼图壁县| 调兵山市| 旺苍县| 秦皇岛市| 如东县| 定结县| 轮台县| 札达县| 徐州市| 随州市| 大渡口区| 郓城县| 泽普县| 汉寿县| 通榆县| 玉门市| 逊克县| 禹城市| 永丰县| 社会| 游戏| 曲靖市| 达孜县| 屏山县| 基隆市| 弥勒县| 鄂温| 玉门市| 武宁县| 吕梁市| 呼图壁县| 上思县| 桐城市| 凤翔县| 四川省| 盖州市| 昭觉县| 濮阳市| 丹阳市| 沙坪坝区| 青阳县|