简体   繁体   English

增加针对Sonar的jacoco集成测试范围

[英]Adding jacoco integration tests coverage for Sonar

Background: I have 2 separate java projects, call them A and B. Project A is the actual product (war application), with unit-tests. 背景:我有2个独立的Java项目,分别称为A和B。项目A是具有单元测试的实际产品(战争应用程序)。 Gradle builds the project and then runs sonar analysis, and I can see the unit-tests coverage in Sonar. Gradle构建了项目,然后进行了声纳分析,我可以在Sonar中看到单元测试的内容。 Project B is an integration test for the first project. 项目B是第一个项目的集成测试。 It is run by Jenkins in a pipeline after building project A and deploying it on an integration-environment. 在构建项目A并将其部署在集成环境中之后,它由Jenkins在管道中运行。 The deployment also involves instrumenting the code so that the jacoco-it report will correlate to Project A's classes. 部署还涉及对代码进行检测,以便jacoco-it报告将与Project A的类相关联。

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? 我的问题:我该如何添加到项目A的声纳页面(目前仅包含单元测试范围,集成测试范围)作为第二步?

The flow I need is: 我需要的流程是:

  1. build project A 建立专案A
  2. run sonar analysis on project A (now it'll show unit-tests coverage on its sonar page) 在项目A上进行声纳分析(现在它将在其声纳页面上显示单元测试范围)
  3. build project B 建立专案B
  4. run sonar analysis on project B - which will simply add integration-coverage to project A on sonar 在项目B上进行声纳分析-它将简单地将集成覆盖范围添加到声纳上的项目A

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. 当我在项目B上进行声纳分析时,它弄乱了项目A的声纳页,从而删除了A的单元测试范围。

The flow that I have now, which is working but I want to change is: 我现在拥有的流程正在运行,但是我想更改的流程是:

  1. build project A 建立专案A
  2. run sonar analysis on project A 对项目A进行声纳分析
  3. build project B 建立专案B
  4. run jacoco report on project B. this outputs the jacoco-it.exec file into a specific location on my disk 在项目B上运行jacoco报告。这会将jacoco-it.exec文件输出到磁盘上的特定位置
  5. run sonar analysis on project A (it has a setting to take the jacoco-it.exec file from the specified location 在项目A上运行声纳分析(它具有从指定位置获取jacoco-it.exec文件的设置
  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. 现在,项目A的声纳页面将同时显示单元测试和集成测试的覆盖范围,但是步骤5完全多余,我想避免这样做。

Any suggestions? 有什么建议么?

what i will suggest is a bit different: 我会建议的有点不同:

  • employ some build automation tool 雇用一些构建自动化工具
  • create a sonar 'checker' job, which doesnt do the full analysis; 创建一个声纳“检查器”工作,它不会做完整的分析; just the incremental, this should break when add quality gate breaker issues 只是增量的,这在添加质量闸断路器问题时应该会中断
  • create a nightly job for your A project with full analysis: -Dsonar.analysis.mode=analysis (note: my experience shows that in this case you must run an incremental prior to this analysis, because in analysis mode sonar accepts new quality gate breaker issues 为您的A项目创建一个-Dsonar.analysis.mode=analysis并进行全面分析: -Dsonar.analysis.mode=analysis (注意:我的经验表明,在这种情况下,您必须在进行此分析之前先进行增量操作,因为声纳在分析模式下会接受新的质量闸门断路器问题
  • i don't think integration tests should count into project test coverage, so that might be just left out. 我认为集成测试不应计入项目测试范围,因此可能会被忽略。

You cannot amend a previous analysis, which is why your 'B' job appears to replace the unit test numbers. 您无法修改先前的分析,这就是为什么您的“ B”工作似乎替代了单元测试编号的原因。 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: 从构建管道的角度来看,这可能会变得很棘手,具体取决于您需要如何构造作业,但是听起来好像您需要3个作业:

  1. build project A 建立专案A
  2. build project B & generate integration test report 建立项目B并生成集成测试报告
  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 作业3从作业2中提取集成测试报告,然后重建项目A或从作业1中提取代码,类和单元测试报告并执行分析

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM