@vinayreddyp87 and I are working on the same project.
We aim to get the delta code coverage between 2 points in time.
My team uses Java + Jacoco + Maven + SonarQube + GIT
Our project has 2 test scenarios.
- JUntis done on CI.
- Integration, GUI and manual testing is done in a different environment post artifact is produced and deployed to Artifactory.
So, whenever we do our CI build we get the code coverage as well “Coverage on the new code” whatever JUnits can cover. BDW leak period is set to “previous_version”. Once an artifact is built we install it in a testing environment where we do GUI testing, manual testing and perform some integration tests along with Jacoco(attached as Java Agent). Now we have two .exec files(Jacoco Binary dump) one from CI and one from the testing environment. These two can be merged using the Jacoco.
Let’s say I got 40% code cover coverage from the CI by Unit testing and 30% from the manual testing and total coverage of 55% using both testings.
How can I get that 55% code coverage on the SonarQube Dashboard and also “code coverage on the new code”?
In one month 1000 lines were added out of which 700 and 500 were covered by Unit and integration testing respectively and 800 distinct lines were covered. I want to get 80% “coverage on new code”.
We need to get this number every month and in between, there are many CI builds meaning many sonar scans.
We can maintain different sonar projects to achieve them.
I thought/tried of these ways.
- Compile the source code, perform Junits, “jacoco-ut.exec” is produced under target\site\jacoco-ut.exec which is uploaded to SonarQube Server to calculate coverage. I can merge this file with the second testing’s jacoco dump. Now, I’ll do a sonar scan which gives me the total code coverage from both testing scenarios.
Now to get “Coverage on the new code”.
I can think of a hack where I do a sonar scan on one-month-old code and pass the merged jacoco dump(Let’s assumed that I preserved those files) to get the total code coverage. Now I update my source code to latest and pass the jacoco dump of the latest testing to the SonarQube server to get both “total coverage” as well as “Coverage on the new code”.
One limitation I have found is that when sonar scan is going on the SCM server should also be in the same state since SonarQube does a “git blame”. So, while I did a scan on one-month-old code my SCM was is the different state given that all are happening on MASER branch.
Please suggest some ways to achieve the “Coverage on the new code” easily since there are blockers to achieve it the ways I mentioned above.