For Java applications, does anyone have any suggestions on how to build a quality gate that would prevent merging new code that does not have at least 80% code coverage? We're working with a legacy codebase, and while we want to see coverage improve there, we want to stop the bleed and enforce proper test coverage on new code going forward.
I've seen suggestions around using git blame and exclusions/inclusions lists in conjunction with SonarQube or JaCoCo, however this would report on coverage for the entire class, not just the new/changed lines, so we could run into an issue there where merges are blocked due to a lack of legacy coverage.
https://github.com/exussum12/coverageChecker
This tool supports Jacoco format and will only error out for changed lines.
this is written in PHP (so you will need PHP installed on your CI server)
If you generate your Jacoco report as normal and then use
git diff origin/master... > diff.txt
./diffFilter --jacoco diff.txt jacoco.xml 80
This will fail on builds where the changed lines have less than 80% coverage (and show a list of missed lines), and pass for anything > 80% (also showing a list of missed lines, if applicable)
This tool will also fail for lack of legacy coverage if you modify old code. (You probably should have at least 1 test for the code you are changing). This may slow some changes down but you will gain coverage in all modified areas which will make things better in the future