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. bootstrap table 横向滚动条

    <table id="AlarmTable" style="overflow:scroll;"/> {title: '名称', field: 'na ...

  2. JAVA中的注释方法

    Java的三种注释方法 ①单行注释:使用 // ,其注释内容从//开始到本行结束,比较常用, 快捷键为:Ctrl + / 或者  Ctrl + Shift + C  取消注释:Ctrl + / 或者  ...

  3. Java实现 LeetCode 399 除法求值

    399. 除法求值 给出方程式 A / B = k, 其中 A 和 B 均为代表字符串的变量, k 是一个浮点型数字.根据已知方程式求解问题,并返回计算结果.如果结果不存在,则返回 -1.0. 示例 ...

  4. 减少if...的使用

    最近维护一批代码,其中包括一堆if...的使用,多的情况嵌套8.9层,痛苦不堪,所以搜寻一些可以降低if...else的方法来改善一下代码,写个简单总结. 第一种: 优化前 if (measuredV ...

  5. portapack h1 买回来刷hackrf与使用说明

    买回来很兴奋,别着急,先不用装扩展板!刷好支持扩展屏的固件,才能用!-------------------------------------hackrf连接电脑windows系统win7/win10 ...

  6. 浅谈Unity的脚本执行顺序

    一.添加脚本的顺序 这是一张官方的脚本顺序图 一般,当我们把脚本绑定在游戏对象上时,或者点击绑定好的脚本的reset按钮时,会调用Reset() 当我们初始化一个对象时,会先调用Awake()在调用O ...

  7. Prometheus监控Docker Swarm集群(一)

    Prometheus监控Docker Swarm集群(一) cAdvisor简介 为了解决容器的监控问题,Google开发了一款容器监控工具cAdvisor(Container Advisor),它为 ...

  8. vue2.0+Element UI 实现动态表单(点击按钮增删一排输入框)

    对于动态增减表单项,Element UI 官方文档表单那一节已经介绍得很清楚了,我之前没有看见,绕了很多弯路,这里针对点击按钮增删一排输入框的问题做一个总结. 效果图如下 存在一排必填的姓名与手机号, ...

  9. jQuery实现购物车商品数量及总价的计算

    记录一下项目中遇到的计算购物车商品数量和总价的jQuery代码,重点在于选择器以及.text()命令的使用. 先上效果图,点击加减,商品数量以及总价会发生相应变化. html代码: <div c ...

  10. Redis学习笔记(二十一) 事务

    文章开始啰嗦两句,写到这里共21篇关于redis的琐碎知识,没有过多的写编程过程中redis的应用,着重写的是redis命令.客户端.服务器以及生产环境搭建用到的主从.哨兵.集群实现原理,如果你真的能 ...