cobertura覆盖率

在姜黄项目中,我们每晚维护一个仪表板。 在仪表板上,我们收集有关项目的统计信息,包括代码覆盖率,findbugs分析和其他指标。 我们一直在使用Maven EMMA插件来提供代码覆盖,但是遇到了EMMA问题。 在对类进行检测后,这会导致测试失败。 因此,由于我们在构建过程中需要准确的测试结果,因此我们禁用了代码覆盖率。 但是,我们仍然需要覆盖代码,更重要的是,我们还需要覆盖现有测试套件,这实际上是一个集成测试套件,而不是单元测试套件。

Cobertura和EMMA插件实际上都是设计用于单元测试的。 因此,我们必须解决该限制。

  1. 首先,我们需要对类进行检测。
  2. 其次,我们需要打包检测的类,并在以后的构建中使用它们。
  3. 需要告诉集成测试为其使用依赖的检测类。
  4. 生成结果的XML报告。

我尝试了这样做,但又没有退缩到ant,但是每次我尝试使用maven-site-plugin并将其配置为生成报告时,都会抱怨cobertura:check配置不正确。 在我们的情况下,我不需要运行检查,只需要生成的报告即可。 于是Ant和AntContrib得以营救。 以下是我想出的完整的Maven个人资料:

<profile><id>cobertura</id><dependencies><dependency><groupId>net.sourceforge.cobertura</groupId><artifactId>cobertura</artifactId><optional>true</optional><version>1.9.4.1</version></dependency></dependencies><build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>cobertura-maven-plugin</artifactId><configuration><instrumentation><excludes><exclude>org/ebayopensource/turmeric/test/**/*.class</exclude><exclude>org/ebayopensource/turmeric/common/v1/**/*.class</exclude></excludes></instrumentation></configuration><executions><execution><id>cobertura-instrument</id><phase>process-classes</phase><goals><goal>instrument</goal></goals></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><executions><execution><id>cobertura-jar</id><phase>post-integration-test</phase><goals><goal>jar</goal></goals><configuration><classifier>cobertura</classifier><classesDirectory>${basedir}/target/generated-classes/cobertura</classesDirectory></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-install-plugin</artifactId><version>2.3.1</version><executions><execution><id>cobertura-install</id><phase>install</phase><goals><goal>install</goal></goals><configuration><classifier>cobertura</classifier></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><executions><execution><phase>verify</phase><configuration><tasks><taskdef classpathref='maven.runtime.classpath'resource='tasks.properties' /><taskdef classpathref='maven.runtime.classpath'resource='net/sf/antcontrib/antcontrib.properties' /><availablefile='${project.build.directory}/cobertura/cobertura.ser'property='ser.file.exists' /><if><equals arg1='${ser.file.exists}'arg2='true' /><then><echo message='Executing cobertura report' /><mkdirdir='${project.build.directory}/site/cobertura' /><cobertura-reportformat='xml'destdir='${project.build.directory}/site/cobertura'datafile='${project.build.directory}/cobertura/cobertura.ser' /></then><else><echo message='No SER file found.' /></else></if></tasks></configuration><goals><goal>run</goal></goals></execution></executions><dependencies><dependency><groupId>ant-contrib</groupId><artifactId>ant-contrib</artifactId><version>20020829</version></dependency></dependencies></plugin></plugins></build></profile>

注意:请勿在此配置文件中使用cobertura:cobertura目标。 它将使构建失败,因为它将尝试对类进行两次检测。

必须使用Ant和AntContrib,因为没有cobertura:report目标,因为它希望在站点生成阶段运行。 但是,这也会导致检查目标也可以运行,而我们并不需要它。 因此,也许,我将制作一个补丁以添加报告目标,以便仅运行报告而不必运行站点目标。 希望这对某些人有帮助,因为我为此付出了很多精力。

祝您编程愉快,别忘了分享!

参考: Intelligent Cramps博客上的JCG合作伙伴 David Carver 使用Cobertura和Maven启用了集成和单元测试的代码覆盖率 。

翻译自: https://www.javacodegeeks.com/2012/09/cobertura-and-maven-code-coverage-for.html

cobertura覆盖率

cobertura覆盖率_Cobertura和Maven:集成和单元测试的代码覆盖率相关推荐

  1. Cobertura和Maven:集成和单元测试的代码覆盖率

    在姜黄项目中,我们每晚维护一个仪表板. 在仪表板上,我们收集有关项目的统计信息,包括代码覆盖率,findbugs分析和其他指标. 我们一直在使用Maven EMMA插件来提供代码覆盖,但是遇到了EMM ...

  2. maven集成spring_Maven集成测试和Spring Restful Services

    maven集成spring 介绍 我的原始博客通过一个非常简单的示例展示了如何分离Maven单元和集成测试. http://johndobie.blogspot.com/2011/06/seperat ...

  3. 个推无法获取个推id_最新个推Android 推送 SDK Maven 集成

    概述 公司准备采用个推作为第三方推送平台,我作为客户端的头号小鸟,掐指一算已经毕业 0.1 年了,Leader 准备把这个简单而又独立的功能点交给我来处理,我紧张兮兮的打开官网集成文档 学习了起来.其 ...

  4. 通过Maven去运行单元测试

    通过Maven去运行单元测试,运行下边的命令 mvn test 他会运行你项目中的所有单元测试类 示范例子 创建两个单元测试类并且通过macen去运行他们,下面是一个简单的待测试类 package c ...

  5. SSM+Maven+Eclipse进行单元测试时提示找不到Config配置项/文件

    场景 在Eclipse+SSM+Maven中进行单元测试时,会提示Config配置文件/信息找不到 原因 在测试类中调用了正常业务中的方法/接口,而在方法中有用到常量的地方, 而常量又是在封装的常量类 ...

  6. java maven junit_【JUnit】JUnit 与 maven 集成

    环境 JDK 11 JUnit 4.13 Spring Tool Suite 4.6.2 Maven 3.6.3 与 maven 集成 因为已经是 maven 项目了,所以不再需要任何东西,默认就与 ...

  7. Maven学习总结(46)——Maven跳过单元测试的两种方法及其区别(-Dmaven.test.skip=true与-DskipTests)

    Maven跳过单元测试有两种命令:-Dmaven.test.skip=true与-DskipTests.其中命令 -DskipTests表示不执行测试用例,但编译测试用例类生成相应的class文件至t ...

  8. 将Maven集成到IDEA

    此刻就把自己在官网上下载的Maven集成到了IDEA,第一次使用Maven需要在远程仓库下载一些东西,点击下图自动下载jar包 如果想看Maven的基础详解可以点击改该链接:Maven基础详解_贺贺学 ...

  9. 将Maven集成到idea中并创建第一个Maven项目

    在将Maven集成到idea中之前,你需要确保你已经安装过了Maven,在DOS下输入mvn -v如果显示如下,则证明已安装,如果没有安装,可以参考Maven的下载安装,如果你不知道Maven的一些基 ...

最新文章

  1. 一文看懂 AI 训练集、验证集、测试集(附:分割方法+交叉验证)
  2. 域上的全矩阵环是单环
  3. 卷积神经网络(CNN)新手指南 1
  4. LSMW批处理使用方法(06)_步骤4、5
  5. QT的QLocale类的使用
  6. leetcode738. 单调递增的数字(贪心)
  7. linux查看执行过的命令行,在Linux命令终端中查看和编辑曾执行过的命令 – LINUX笔记 – CFEI.NET...
  8. 论文浅尝 - ISWC2020 | KnowlyBERT: 知识图谱结合语言模型补全图谱查询
  9. 漂亮大气注册登录页面模板
  10. Maven的依赖范围
  11. 时至 2018 年,还有必要学 Vim 吗?
  12. KMP模式匹配算法程序(Python,C++,C)
  13. 【问题解决方案】Markdown正文中慎用星号否则容易变斜体
  14. 偶然的相遇【我与51CTO的故事】
  15. 【Shiro第三篇】SpringBoot + Shiro实现用户认证(密码加密)
  16. STM32 vcap引脚
  17. 三大抽样分布:卡方分布,t分布和F分布
  18. 安卓优雅的svg实践绚丽效果
  19. 世界编程语言排名2019_世界十大编程语言-2019一起玩
  20. NeurIPS 2021 放榜!旷视研究院5篇接收论文亮点解读!

热门文章

  1. 【php】php对mysql的连接操作【mysql】
  2. C#实现人脸识别【SqlHelper】
  3. javaWeb服务详解(含源代码,测试通过,注释) ——applicationContext.xml
  4. Mysql对字符串去掉前后空格(trim)或者指定字符
  5. python画建筑_专题 | Python 绘图入门
  6. hash地址_一致性Hash在负载均衡中的应用
  7. 转:权限管理——用户认证和用户授权
  8. Java Springboot应用部署
  9. 静态资源Css基础语法
  10. quarkus_使用Quarkus调试容器中的系统测试(视频)