{"id":817,"date":"2017-09-01T22:17:59","date_gmt":"2017-09-01T12:17:59","guid":{"rendered":"http:\/\/juliangamble.com\/blog\/?p=817"},"modified":"2019-11-30T14:15:16","modified_gmt":"2019-11-30T03:15:16","slug":"commit-level-coverage-reporting","status":"publish","type":"post","link":"https:\/\/juliangamble.com\/blog\/2017\/09\/01\/commit-level-coverage-reporting\/","title":{"rendered":"Commit Level Coverage Reporting"},"content":{"rendered":"<h3>What is it?<\/h3>\n<p>This enables coverage reporting showing lines not covered on each commit<\/p>\n<h3>Where is it?<\/h3>\n<p><a href=\"https:\/\/github.com\/juliangamble\/commit-level-coverage-report\">https:\/\/github.com\/juliangamble\/commit-level-coverage-report<\/a><\/p>\n<h3>Is there an example project?<\/h3>\n<p><a href=\"https:\/\/github.com\/juliangamble\/jacoco-example-project\">https:\/\/github.com\/juliangamble\/jacoco-example-project<\/a><\/p>\n<h3>Why you would use this<\/h3>\n<p>[Workplace with a million line codebase and 100s of developers working on it.]<\/p>\n<p>Tech Lead: &#8220;We really want to get the coverage up on this codebase &#8211; more tests will give us more feedback about the code.&#8221;<\/p>\n<p>Developer: &#8220;Well that&#8217;s lovely, but I really need to ship my feature &#8211; I&#8217;ll make sure my stuff is covered as best I can.&#8221;<\/p>\n<p>Tech Lead: &#8220;Ok &#8211; how much coverage are you aiming for?&#8221;<\/p>\n<p>Developer: &#8220;I&#8217;ll make sure the lines I touch have coverage.&#8221;<\/p>\n<p>Tech Lead: &#8220;Ok &#8211; how will you measure that?&#8221; &#8230;.<\/p>\n<p>Now obviously:<\/p>\n<p>(a) this codebase is a candidate for modularisation and<\/p>\n<p>(b) sonar does give you feedback on coverage at a commit level &#8211; but sonar doesn&#8217;t give you a way to know what the commit-level coverage is prior to pushing your changes. ie &#8211; if you&#8217;ve missed some coverage on the lines you&#8217;ve changed &#8211; there isn&#8217;t a way to know before pushing.<\/p>\n<p>This change is trying to solve the problem of knowing &#8220;for the lines I have touched &#8211; what coverage have I got? What lines have I missed?&#8221;<\/p>\n<h3><a id=\"user-content-how-to-setup-and-use-in-your-project\" class=\"anchor\" href=\"https:\/\/github.com\/juliangamble\/commit-level-coverage-report#how-to-setup-and-use-in-your-project\"><\/a>How to setup and use in your project<\/h3>\n<p>Add the following into your\u00a0<code>pom.xml<\/code><\/p>\n<pre><code>&lt;project&gt;\r\n    &lt;build&gt;\r\n        &lt;plugins&gt;\r\n            &lt;plugin&gt;\r\n                &lt;groupId&gt;com.github.juliangamble&lt;\/groupId&gt;\r\n                &lt;artifactId&gt;commit-level-coverage-report&lt;\/artifactId&gt;\r\n                &lt;version&gt;1.0&lt;\/version&gt;\r\n                &lt;executions&gt;\r\n                    &lt;execution&gt;\r\n                        &lt;id&gt;post-unit-test2&lt;\/id&gt;\r\n                        &lt;phase&gt;test&lt;\/phase&gt;\r\n                        &lt;goals&gt;\r\n                            &lt;goal&gt;report-on-commit-coverage&lt;\/goal&gt;\r\n                        &lt;\/goals&gt;\r\n                        &lt;configuration&gt;\r\n                            &lt;!-- Optional - sets the path to the file which contains the execution data. --&gt;\r\n                            &lt;!-- &lt;dataFile&gt;${project.build.directory}\/coverage-reports\/jacoco.exec&lt;\/dataFile&gt; --&gt;\r\n                            &lt;!-- Sets the output directory for the code coverage report. --&gt;\r\n                            &lt;outputDirectory&gt;${project.reporting.outputDirectory}\/&lt;\/outputDirectory&gt;\r\n                            &lt;daysBackToCheck&gt;100&lt;\/daysBackToCheck&gt;\r\n                        &lt;\/configuration&gt;\r\n                    &lt;\/execution&gt;\r\n                &lt;\/executions&gt;\r\n            &lt;\/plugin&gt;\r\n        &lt;\/plugins&gt;\r\n    &lt;\/build&gt;\r\n&lt;\/project&gt;\r\n<\/code><\/pre>\n<p>Then run this:<\/p>\n<pre><code>mvn clean test\r\n<\/code><\/pre>\n<h3><a id=\"user-content-example-result\" class=\"anchor\" href=\"https:\/\/github.com\/juliangamble\/commit-level-coverage-report#example-result\"><\/a>Example Result<\/h3>\n<pre><code>----\r\nCommit: caaa32f8c8eff580b4760f60dbf021d6e03935c3 - Sun Jul 16 20:48:50 AEST 2017 - Julian Gamble - [dev] first drop\r\n\r\nsource file name: \/com\/machiavellian\/MyApplication.java\r\nIntersection of line changes with coverage (lines we care about): 4\r\ncovered lines: 3\r\nCoverage for commit: 75%\r\nLines not covered: 1\r\nsrc\/main\/java\/com\/machiavellian\/MyApplication.java:11         return firstArg - secondArg;\r\n\r\n----\r\nCommit: 57bfb7956b501afca5fc101753d6e284d448f4ce - Sun Jul 16 20:53:59 AEST 2017 - Julian Gamble - [dev] adding new method\r\n\r\nIntersection of line changes with coverage (lines we care about): 1\r\ncovered lines: 1\r\nCoverage for commit: 100%\r\nLines not covered: 0\r\n----\r\nCommit: acf35680891d1f853a226035981c1ac18d9f50a2 - Sun Jul 16 20:55:58 AEST 2017 - Julian Gamble - [dev] adding coverage\r\n\r\nIntersection of line changes with coverage (lines we care about): 0\r\ncovered lines: 0\r\nCoverage for commit: 0%\r\nLines not covered: 0\r\n----\r\nCommit: 9c42a1ab1e8db57e31e17837120da6dc257dbb72 - Sun Jul 16 20:56:23 AEST 2017 - Julian Gamble - [dev] adding divide method\r\n\r\nIntersection of line changes with coverage (lines we care about): 1\r\ncovered lines: 0\r\nCoverage for commit: 0%\r\nLines not covered: 1\r\nsrc\/main\/java\/com\/machiavellian\/MyApplication.java:19         return firstArg \/ secondArg;\r\n\r\n----\r\n<\/code><\/pre>\n<h3><a id=\"user-content-result-file-location\" class=\"anchor\" href=\"https:\/\/github.com\/juliangamble\/commit-level-coverage-report#result-file-location\"><\/a>Result File Location<\/h3>\n<pre><code>target\/site\/coverage-per-commit.txt\r\n<\/code><\/pre>\n<h1><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>What is it? This enables coverage reporting showing lines not covered on each commit Where is it? https:\/\/github.com\/juliangamble\/commit-level-coverage-report Is there an example project? https:\/\/github.com\/juliangamble\/jacoco-example-project Why you would use this [Workplace with a million line codebase and 100s of developers working &hellip; <a href=\"https:\/\/juliangamble.com\/blog\/2017\/09\/01\/commit-level-coverage-reporting\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-817","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/comments?post=817"}],"version-history":[{"count":2,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/817\/revisions"}],"predecessor-version":[{"id":856,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/posts\/817\/revisions\/856"}],"wp:attachment":[{"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/media?parent=817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/categories?post=817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/juliangamble.com\/blog\/wp-json\/wp\/v2\/tags?post=817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}