为Sonar添加jacoco集成测试覆盖率 [英] Adding jacoco integration tests coverage for Sonar

查看:1578
本文介绍了为Sonar添加jacoco集成测试覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:
我有两个独立的java项目,称它们为A和B.
项目A是实际产品(战争应用程序),带有单元测试。 Gradle构建项目,然后运行声纳分析,我可以看到Sonar中的单元测试覆盖率。
项目B是第一个项目的集成测试。它由Jenkins在构建项目A并将其部署到集成环境后进行管道运行。部署还涉及对代码进行检测,以便jacoco-it报告将与项目A的类关联。



我的问题:
如何添加到项目A声纳页面,目前只有单元测试覆盖率,集成测试覆盖率 - 作为第二步?

我需要的流量是:


  1. 构建项目A对项目A运行声纳分析(现在它将在其声纳页面上显示单元测试覆盖率)

  2. 构建项目B

  3. 运行项目B的声纳分析 - 只需在声纳上添加项目A的整合覆盖率
  4. $ b

目前无法使用。当我在项目B上运行声纳分析时,它弄乱了项目A的声纳页面,取消了A的单元测试范围。



我现在正在运行的流程但我想改变的是:
$ b


  1. 生成项目A

  2. 对项目A运行声纳分析

  3. 生成项目B

  4. 在项目B上运行jacoco报告。这会将jacoco-it.exec文件输出到磁盘上的特定位置

  5. 对项目A运行声纳分析(它具有从指定位置获取jacoco-it.exec文件的设置)现在项目A的声纳页将显示包括单元测试和集成测试的覆盖率,但第5步完全是多余的,我想避免它。

有什么建议吗? / p>

解决方案

你不能修改以前的分析,这就是为什么你的'B'工作似乎取代了单元测试数字。要做的就是生成你的集成测试覆盖率端口进行分析,并使该报告可用,以便可以在同一分析中读取单元测试和集成测试编号。

从构建流水线的角度来看,棘手的问题取决于你需要如何构建工作,但副手听起来像你需要3个工作:


  1. 构建项目A

  2. build project B&生成集成测试报告
  3. 作业3从作业2中提取集成测试报告,并重新构建项目A或从作业1中提取代码,类和单元测试报告并执行分析


Background: I have 2 separate java projects, call them A and B. Project A is the actual product (war application), with unit-tests. Gradle builds the project and then runs sonar analysis, and I can see the unit-tests coverage in Sonar. Project B is an integration test for the first project. It is run by Jenkins in a pipeline after building project A and deploying it on an integration-environment. The deployment also involves instrumenting the code so that the jacoco-it report will correlate to Project A's classes.

My question: How can I add to project A's sonar page, which currently has only unit-tests coverage, the integration tests coverage - as a second step?

The flow I need is:

  1. build project A
  2. run sonar analysis on project A (now it'll show unit-tests coverage on its sonar page)
  3. build project B
  4. run sonar analysis on project B - which will simply add integration-coverage to project A on sonar

It's currently not working. when I run sonar analysis on project B it messes up project A's sonar page, removing the unit-test coverage of A.

The flow that I have now, which is working but I want to change is:

  1. build project A
  2. run sonar analysis on project A
  3. build project B
  4. run jacoco report on project B. this outputs the jacoco-it.exec file into a specific location on my disk
  5. run sonar analysis on project A (it has a setting to take the jacoco-it.exec file from the specified location
  6. now project A's sonar page will show both unit-tests and integration-tests coverage, but step 5 is completely redundant and I want to avoid it.

Any suggestions?

解决方案

You cannot amend a previous analysis, which is why your 'B' job appears to replace the unit test numbers. What you need to do is generate your integration test coverage report before analysis, and make that report available so that both unit test and integration test numbers can be read in the same analysis.

From a build pipeline standpoint, that could get tricky depending on how you need to structure the jobs, but off-hand it sounds like you need 3 jobs:

  1. build project A
  2. build project B & generate integration test report
  3. job 3 pulls integration test report from job 2, and either rebuilds project A or pulls code, classes, and unit test report from job 1 and performs analysis

这篇关于为Sonar添加jacoco集成测试覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆