My hypothethical scenario is this:
Now the intersection of my git diff and the jacoco information is that 7 of the 10 lines of code changed are covered. ie - I have 70% coverage on new code.
But I had to work that out manually.
I'd like an automated way to work out the percentage how many new lines of code are covered.
My question is: Is there a way to get unit coverage percentage (eg from jacoco) on only new code?
(Note I know sonarqube can do this if you run the scanner with analysis.mode=publish
and get interrogate the task result with the JSON API - I'm looking for something lightweight that a developer can run locally.)
Step 4: To get you code coverage report navigate to the target > site > jacoco > index.html > right-click > Open In > Browser > And your preferred browser. So basically index.html is your code code coverage report file. So you can see your report will be shown like this and the percentage completely depends on how you have written the test cases.
This tutorial describes the usage of the Jacoco, which can be used to check the code coverage of Java projects. 1. Jacoco Jacoco is an open source project, which can be used to check production code for test code coverage. It creates reports and integrates well with IDEs like the Eclipse IDE.
The 38 instructions shown by JaCoCo in the report refer to the bytecode instructions instead of Java code instructions. The JaCoCo reports help you visually analyze code coverage by using diamonds with colors for branches and background highlight colors for lines. A brief explanation of the diamonds seen in the code coverage report is below:
You can run maven clean verify to check whether the rules set in jacoco:check goal are met or not. The log shows “All coverage checks have been met.” as our code coverage score is 94% which is greater than our minimum 50%.
There are two plugins:
Both are built on top of JaCoCo and able to generate JaCoCo like reports.
Also, they able to fail the build if your coverage ratio is less than expected(the ratio colud be configured by the plugins)
Jacoco + diff-cover
It is work for me. CI Shell script:
export PATH="${jobPath}"/buildbox/Python-3.8.2/bin:$PATH
python --version
python -m pip install -i http://xx.xx.xx.com/artifactory/api/pypi/xx-pypi-public/simple/ --trusted-host xx.xx.xx.com diff_cover==4.0.1
mvn clean test -Dmaven.test.failure.ignore=true
diff-cover "${WORKSPACE}"/xxx-test/target/site/jacoco/jacoco.xml --compare-branch origin/"${target_branch}" --src-roots $(find . -name java -type d | grep 'src/main/java$' | egrep -v "target|test|testkit") --html-report ${WORKSPACE}/xxx-test/target/site/jacoco/index.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With