junit配合catubuter统计单元测试的代码覆盖率
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> <!-- 定义 cobertura 的ant task -->
<taskdef classpath="cobertura.jar" resource="tasks.properties" classpathref="complie-path" />
<!-- 为源码添加日志代码,放到 instrumented-classes 目录 -->
<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>
junit配合catubuter统计单元测试的代码覆盖率的更多相关文章
- TestNG配合catubuter统计单元测试的代码覆盖率
build-testNG.xml对应的ant脚本为 <?xml version="1.0" encoding="UTF-8"?> <proje ...
- 使用coverlet统计单元测试的代码覆盖率
单元测试是个好东西, 可以在一定程度上兜底 虽然写单元测试这件事情非常麻烦 但是好的单元测试可以显著提高代码质量, 减少bug, 避免无意中的修改导致其他模块出错 写测试用例的过程中, 靠人力去确保所 ...
- Java开发工具IntelliJ IDEA单元测试和代码覆盖率图解
原文 http://www.cnblogs.com/xiongmaopanda/p/3314660.html Java开发工具IntelliJ IDEA使用教程:单元测试和代码覆盖率 本文将展示如何使 ...
- Jenkins构建Android项目持续集成之单元测试及代码覆盖率
单元测试 在软件开发中一直在推崇TDD(测试驱动开发),但是一直不能被有效的执行或者并不是真正的测试驱动开发(先开发后写单元测试),因为我们懒!而Android开发又是大多应用层面的开发,很多都是和视 ...
- VS2013单元测试及代码覆盖率分析--Xunit
1,Javaweb中有jmeter.jacoco.ant.badboy等集成测试代码覆盖率的方式,C#代码的覆盖率怎么测试呢?VS2013的IDE上本身并未集成测试的工具,以下讲解VS2013中C#代 ...
- [Azure Devops] 获取单元测试的代码覆盖率
1. 获取代码覆盖率 上一篇文章里,我们在 Pipeline 中插入一个单元测试并把所有单元测试都通过作为 Pipeline 通过的硬性要求.除此以外,我们还可以获取单元测试的代码覆盖率,用作衡量代码 ...
- 使用JaCoCo统计单元测试代码覆盖率
1 JaCoCo介绍 JaCoCo是EclEmma团队基于多年覆盖率库使用经验总结而研发的一个开源的Java代码覆盖率库. 2 JaCoCo覆盖率计数器 JaCoCo 包含了多种尺度的覆盖率计数器(C ...
- 【week3】词频统计 单元测试
使用Eclipse 集成的Junit进行单元测试.单元测试的核心包括断言.注解. 测试代码如下: @BeforeClass // 针对所有测试,只执行一次,且必须为static void public ...
- Eclipse使用EclEmma看单元测试的代码覆盖率
在开发过程中,我们应该养成编写本地单元测试用例的好习惯,甚至做到测试驱动开发.EclEmma是Eclipse的一个插件,是一款测试用例的代码覆盖率统计工具,能明确到哪一行在测试过程中被调用到了.这里不 ...
随机推荐
- Shell概述1
Shell概述1 脚本文件内容(vim ex2) #!/bin/bash #If no arguments,then listing the current directory. #Otherwise ...
- 如何管理win系列服务器,win10 pro如何 使用远程桌面
远程桌面,大家都理解,专业的运维人员都是连接上百台服务器进行操作管理工作. 先介绍一款专业的远程桌面管理工具:iis7远程桌面批量管理 win10 pro如何 使用远程桌面? 一. 首先在win10 ...
- 面试题: hashset如何保证值不会被重复的
个人博客网:https://wushaopei.github.io/ (你想要这里多有) 众所周知,HashSet 的值是不可能被重复的,在业务上经常被用来做数据去重的操作,那么,其内部究竟是怎 ...
- Java实现 LeetCode 336 回文对
336. 回文对 给定一组唯一的单词, 找出所有不同 的索引对(i, j),使得列表中的两个单词, words[i] + words[j] ,可拼接成回文串. 示例 1: 输入: ["abc ...
- Java实现LeetCode_0035_SearchInsertPosition
package javaLeetCode.primary; public class SearchInsertPosition_35 { public static void main(String[ ...
- JavaScript使用for循环和splice删除数组指定元素的注意点
在JavaScript里可以结合for循环和splice来删除数组指定的元素.但是要注意删除元素后,数组索引会发生改变 示例 var arr = ["a","b" ...
- Burpsuite intruder模块 越过token进行爆破,包含靶场搭建
安装靶场 链接:https://pan.baidu.com/s/19X0oC63oO2cQKK6UL5xgOw 提取码:yq7f 下载完成放入网站根目录 点击初始化安装 出现错误,进行跟踪 发现是数据 ...
- 温故知新-多线程-Cache Line存在验证
文章目录 简述 缓存行Cache Line 验证CacehLine存在? 参考 你的鼓励也是我创作的动力 Posted by 微博@Yangsc_o 原创文章,版权声明:自由转载-非商用-非衍生-保持 ...
- QingStor 对象存储架构设计及最佳实践
对象存储概念及特性 在介绍 QingStor️对象存储内部的的架构和设计原理之前,我们首先来了解一下对象存储的概念,也就是从外部视角看,对象存储有什么特性,我们应该如何使用. 对象存储本质上是一款存储 ...
- [Linux之旅一] .NET Core 2.2部署到Docker中
第一步,使用VS2017或者VS2019创建.NET Core 2.2或3.1的项目,如下图: 在创建项目的时候记得勾选Docker支持,这样会自动创建Dockerfile文件,这个文件用于构建Doc ...