热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

junit配合catubuter统计单元测试的代码覆盖率

1、视频参考孔浩老师ant视频笔记 对应的build-junit.xml脚步如下所示:

1、视频参考孔浩老师ant视频笔记


 对应的build-junit.xml脚步如下所示:

xml version="1.0" encoding="UTF-8"?>
<project default="coverage-report">
<property name="src.dir" location="src">property>
<property name="test.src.dir" location="test">property>
<property name="web.dir" location="WebRoot">property>
<property name="conf.dir" location="conf">property>
<property name="web.web-info.dir" location="${web.dir}/WEB-INF">property>
<property name="lib.dir" location="${web.web-info.dir}/lib">property>
<property name="build.dir" location="build">property>
<property name="build.classes" location="${build.dir}/classes">property>
<property name="test.dir" location="${build.dir}/test/">property>
<property name="test.classes.dir" location="${test.dir}/classes">property>
<property name="test.report.dir" location="${test.dir}/report">property>
<property name="build.jar.dir" location="${build.dir}/dist">property>
<property name="build.zip.dir" location="${build.dir}/zip">property>
<property name="build.doc.dir" location="${build.dir}/doc">property>
<property name="build.src" location="${build.dir}/src">property>
<property name="instrumented_classes" value="${test.dir}/instrumented-classes" />
<property name="cobertura_report" value="${test.dir}/cobertura-report" />


<path id="complie-path">
<fileset dir="${lib.dir}" includes="**/*.jar">fileset>
path>

<path id="complie-test-path">
<path refid="complie-path">path>
<pathelement location="${build.classes}"/>
path>

<path id="run-test-path">
<path refid="complie-test-path">path>
<pathelement location="${test.classes.dir}"/>
path>

<path id="cobertura-run-path">
<path refid="complie-path">path>
<pathelement location="${test.classes.dir}"/>
<pathelement location="${instrumented_classes}"/>
path>

<target name="clean">
<delete dir="${build.dir}">delete>
target>

<target name="init" depends="clean" >
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.classes}"/>
<mkdir dir="${test.dir}"/>
<mkdir dir="${test.classes.dir}"/>
<mkdir dir="${test.report.dir}"/>
<mkdir dir="${build.jar.dir}"/>
<mkdir dir="${build.zip.dir}"/>
<mkdir dir="${build.doc.dir}"/>
<mkdir dir="${build.src}"/>
<mkdir dir="${instrumented_classes}"/>
<mkdir dir="${cobertura_report}"/>
target>

<target name="compile" depends="init">
<javac destdir="${build.classes}" srcdir="${src.dir}" includeantruntime="true"
classpathref
="complie-path">
javac>

<copy todir="${build.classes}" >
<fileset dir="${src.dir}" excludes="**/*.java">fileset>
copy>
target>

<target name="compile-test" depends="compile">
<javac destdir="${test.classes.dir}" srcdir="${test.src.dir}" includeantruntime="true"
classpathref
="complie-test-path">
javac>
<copy todir="${test.classes.dir}" >
<fileset dir="${test.src.dir}" excludes="**/*.java">fileset>
copy>

target>


<target name="run-test" depends="compile-test">

<junit printsummary="true" haltonfailure="no" showoutput="true" failureproperty="junit.fail">
<classpath refid="run-test-path">
classpath>
<formatter type="xml" usefile="true"/>
<batchtest fork="yes" todir="${test.report.dir}">
<fileset dir="${test.classes.dir}">
<include name="**/Test*.class"/>
fileset>
batchtest>
junit>

<junitreport todir="${test.report.dir}">
<fileset dir="${test.report.dir}">
<include name="TEST-*.xml"/>
fileset>
<report format="frames" todir="${test.report.dir}/html"/>
junitreport>
<fail if="${junit.fail}" message="单元测试运行失败,请查看:${test.report.dir}/html"/>
target>





<taskdef classpath="cobertura.jar" resource="tasks.properties" classpathref="complie-path" />

<target name="instrument" depends="run-test">
<cobertura-instrument todir="${instrumented_classes}">
<fileset dir="${build.classes}">
<include name="**/*.class" />
fileset>
cobertura-instrument>
target>


<target name="cover-test" depends="instrument">
<junit printsummary="yes" fork="yes" haltonfailure="no" >
<classpath refid="cobertura-run-path">classpath>
<formatter type="xml" usefile="true"/>
<batchtest fork="yes" todir="${test.report.dir}">
<fileset dir="${test.classes.dir}">
<include name="**/Test*.class"/>
fileset>
batchtest>
junit>
target>


<target name="coverage-report" depends="cover-test">
<cobertura-report srcdir="${src.dir}" destdir="${cobertura_report}"/>
target>



project>

 



推荐阅读
author-avatar
落雪念伯言
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有