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统计单元测试的代码覆盖率的更多相关文章

  1. TestNG配合catubuter统计单元测试的代码覆盖率

    build-testNG.xml对应的ant脚本为 <?xml version="1.0" encoding="UTF-8"?> <proje ...

  2. 使用coverlet统计单元测试的代码覆盖率

    单元测试是个好东西, 可以在一定程度上兜底 虽然写单元测试这件事情非常麻烦 但是好的单元测试可以显著提高代码质量, 减少bug, 避免无意中的修改导致其他模块出错 写测试用例的过程中, 靠人力去确保所 ...

  3. Java开发工具IntelliJ IDEA单元测试和代码覆盖率图解

    原文 http://www.cnblogs.com/xiongmaopanda/p/3314660.html Java开发工具IntelliJ IDEA使用教程:单元测试和代码覆盖率 本文将展示如何使 ...

  4. Jenkins构建Android项目持续集成之单元测试及代码覆盖率

    单元测试 在软件开发中一直在推崇TDD(测试驱动开发),但是一直不能被有效的执行或者并不是真正的测试驱动开发(先开发后写单元测试),因为我们懒!而Android开发又是大多应用层面的开发,很多都是和视 ...

  5. VS2013单元测试及代码覆盖率分析--Xunit

    1,Javaweb中有jmeter.jacoco.ant.badboy等集成测试代码覆盖率的方式,C#代码的覆盖率怎么测试呢?VS2013的IDE上本身并未集成测试的工具,以下讲解VS2013中C#代 ...

  6. [Azure Devops] 获取单元测试的代码覆盖率

    1. 获取代码覆盖率 上一篇文章里,我们在 Pipeline 中插入一个单元测试并把所有单元测试都通过作为 Pipeline 通过的硬性要求.除此以外,我们还可以获取单元测试的代码覆盖率,用作衡量代码 ...

  7. 使用JaCoCo统计单元测试代码覆盖率

    1 JaCoCo介绍 JaCoCo是EclEmma团队基于多年覆盖率库使用经验总结而研发的一个开源的Java代码覆盖率库. 2 JaCoCo覆盖率计数器 JaCoCo 包含了多种尺度的覆盖率计数器(C ...

  8. 【week3】词频统计 单元测试

    使用Eclipse 集成的Junit进行单元测试.单元测试的核心包括断言.注解. 测试代码如下: @BeforeClass // 针对所有测试,只执行一次,且必须为static void public ...

  9. Eclipse使用EclEmma看单元测试的代码覆盖率

    在开发过程中,我们应该养成编写本地单元测试用例的好习惯,甚至做到测试驱动开发.EclEmma是Eclipse的一个插件,是一款测试用例的代码覆盖率统计工具,能明确到哪一行在测试过程中被调用到了.这里不 ...

随机推荐

  1. Spring Boot笔记(四) springboot 集成 @Scheduled 定时任务

    个人博客网:https://wushaopei.github.io/    (你想要这里多有) 1.在SpringBoot 项目中使用@Scheduled注解执行定时任务: 配置pom.xml 依赖: ...

  2. 一招解决GitHub致命的下载速度(GitHub下载速度慢怎么办)

    通过码云来导入github,通过码云下载 第一步: 找一个你需要下载的GitHub项目 第二步: 复制链接 第三步: 打开码云,然后选择从GitHub导入 第四步: 复制刚才的连接,起个名字,点击导入 ...

  3. Java实现 LeetCode 443 压缩字符串

    443. 压缩字符串 给定一组字符,使用原地算法将其压缩. 压缩后的长度必须始终小于或等于原数组长度. 数组的每个元素应该是长度为1 的字符(不是 int 整数类型). 在完成原地修改输入数组后,返回 ...

  4. Java实现 LeetCode 395 至少有K个重复字符的最长子串

    395. 至少有K个重复字符的最长子串 找到给定字符串(由小写字符组成)中的最长子串 T , 要求 T 中的每一字符出现次数都不少于 k .输出 T 的长度. 示例 1: 输入: s = " ...

  5. Java实现Fibonacci取余

    Description Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1. 当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少. Input 多 ...

  6. Java中TreeSet的详细用法

    第1部分 TreeSet介绍 TreeSet简介 TreeSet 是一个有序的集合,它的作用是提供有序的Set集合.它继承于AbstractSet抽象类,实现了NavigableSet, Clonea ...

  7. Java 虚拟机是如何判定两个 Java 类是相同的?

    Java 虚拟机是如何判定两个 Java 类是相同的? 答:Java 虚拟机不仅要看类的全名是否相同,还要看加载此类的类加载器是否一样.只有两者都相同的情况,才认为两个类是相同的.即便是同样的字节代码 ...

  8. java实现求二十一位水仙花数(21位水仙花数)

    一个N位的十进制正整数,如果它的每个位上的数字的N次方的和等于这个数本身,则称其为花朵数. 例如: 当N=3时,153就满足条件,因为 1^3 + 5^3 + 3^3 = 153,这样的数字也被称为水 ...

  9. Java实现第十届蓝桥杯特别数的和

    试题 F: 特别数的和 时间限制: 1.0s 内存限制: 512.0MB 本题总分:15 分 [问题描述] 小明对数位中含有 2.0.1.9 的数字很感兴趣(不包括前导 0),在 1 到 40 中这样 ...

  10. 数据结构:用实例分析ArrayList与LinkedList的读写性能

    目录 背景 ArrayList LinkedList 实例分析 1.增加数据 2.插入数据 3.遍历数据 3.1.LinkedList遍历改进 总结 背景 ArrayList与LinkedList是J ...