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. 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:

  • build project A
  • run sonar analysis on project A (now it'll show unit-tests coverage on its sonar page)
  • build project B
  • 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:

  • build project A
  • run sonar analysis on project A
  • build project B
  • run jacoco report on project B. this outputs the jacoco-it.exec file into a specific location on my disk
  • run sonar analysis on project A (it has a setting to take the jacoco-it.exec file from the specified location
  • 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?


    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
  • 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. 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:

  • build project A
  • build project B & generate integration test report
  • 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
  • 链接地址: http://www.djcxy.com/p/59908.html

    上一篇: 配置声呐以查看集成测试(v6.2)

    下一篇: 为Sonar添加jacoco集成测试覆盖率