{"id":889,"date":"2022-05-12T16:27:58","date_gmt":"2022-05-12T13:27:58","guid":{"rendered":"https:\/\/www.juustila.com\/antti\/?p=889"},"modified":"2022-05-12T16:31:12","modified_gmt":"2022-05-12T13:31:12","slug":"coverage-fight","status":"publish","type":"post","link":"https:\/\/www.juustila.com\/antti\/2022\/05\/12\/coverage-fight\/","title":{"rendered":"Coverage fight"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Well it was a fight but got the code coverage working with VS Code \/ Java and Coverage Gutters extension. Doing this for an exercise under preparation for the next Fall course on Data Structures and Algorithms. Probably this is just a demo or something students may take a look at, not a required task.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"722\" src=\"https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30-1024x722.png\" alt=\"\" class=\"wp-image-890\" srcset=\"https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30-1024x722.png 1024w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30-300x211.png 300w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30-768x541.png 768w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30-1536x1083.png 1536w, https:\/\/www.juustila.com\/antti\/wp-content\/uploads\/2022\/05\/Nayttokuva-2022-5-12-kello-16.16.30.png 1745w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><figcaption> Code coverage visible, YEAH!!<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">What I have in the Maven <code>pom.xml<\/code> currently is <\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-small-font-size\">&lt;argLine&gt;-Xmx2048m&lt;\/argLine&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">within the <code>properties<\/code> struct, and in the <code>build\/plugins<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;plugin&gt;\n   &lt;artifactId&gt;maven-failsafe-plugin&lt;\/artifactId&gt;  \n   &lt;version&gt;2.22.2&lt;\/version&gt;\n      &lt;configuration&gt;\n        &lt;argLine&gt;${argLine} -Xmx4096m -XX:MaxPermSize=512M ${itCoverageAgent}&lt;\/argLine&gt;\n      &lt;\/configuration&gt;\n&lt;\/plugin&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and the whole jacoco plugin structure is here, under the <code>build\/plugins<\/code> structure (with some commented out sections):<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>&lt;plugin>\n    &lt;groupId>org.jacoco&lt;\/groupId>\n    &lt;artifactId>jacoco-maven-plugin&lt;\/artifactId>\n    &lt;version>0.8.8&lt;\/version>\n    &lt;executions>\n        &lt;execution>\n            &lt;id>pre-unit-test&lt;\/id>\n            &lt;goals>\n                &lt;goal>prepare-agent&lt;\/goal>\n            &lt;\/goals>\n            &lt;configuration>\n                &lt;!-- Sets the path to the file which contains the execution data. -->\n                &lt;dataFile>${project.build.directory}\/jacoco.exec&lt;\/dataFile>\n                &lt;outputDirectory>${project.reporting.outputDirectory}\/jacoco&lt;\/outputDirectory>\n                &lt;propertyName>surefireArgLine&lt;\/propertyName>\n            &lt;\/configuration>\n        &lt;\/execution>\n        &lt;!-- Ensures that the code coverage report for unit tests is created \n              after unit tests have been run. -->\n        &lt;execution>\n            &lt;id>post-unit-test&lt;\/id>\n            &lt;phase>test&lt;\/phase>\n            &lt;goals>\n                &lt;goal>report&lt;\/goal>\n            &lt;\/goals>\n            &lt;configuration>\n                &lt;!-- Sets the path to the file which contains the execution data. -->\n                &lt;dataFile>${sonar.jacoco.reportPath}&lt;\/dataFile>\n                &lt;!-- Sets the output directory for the code coverage report. -->\n                &lt;outputDirectory>${jacoco.path}&lt;\/outputDirectory>\n            &lt;\/configuration>\n        &lt;\/execution>\n        &lt;execution>\n            &lt;id>default-report&lt;\/id>\n            &lt;goals>&lt;\/goals>\n            &lt;configuration>\n                &lt;dataFile>${project.build.directory}\/jacoco.xml&lt;\/dataFile>\n                &lt;outputDirectory>${project.reporting.outputDirectory}\/jacoco&lt;\/outputDirectory>\n            &lt;\/configuration>\n        &lt;\/execution>\n        &lt;execution>\n            &lt;id>jacoco-check&lt;\/id>\n            &lt;goals>\n                &lt;goal>check&lt;\/goal>\n            &lt;\/goals>\n            &lt;configuration>\n                &lt;rules>\n                    &lt;rule>\n                        &lt;element>PACKAGE&lt;\/element>\n                        &lt;limits>\n                            &lt;limit>\n                                &lt;counter>LINE&lt;\/counter>\n                                &lt;value>COVEREDRATIO&lt;\/value>\n                                &lt;minimum>0.0&lt;\/minimum>\n                            &lt;\/limit>\n                        &lt;\/limits>\n                    &lt;\/rule>\n                &lt;\/rules>\n            &lt;\/configuration>\n        &lt;\/execution>\n    &lt;\/executions>\n&lt;\/plugin><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and finally, you need to build from the command line with this Maven command:<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>mvn jacoco:prepare-agent package jacoco:report<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So when viewing the code then, you can see the code coverage colors in the code editor sidebar on the left.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Well it was a fight but got the code coverage working with VS Code \/ Java and Coverage Gutters extension. Doing this for an exercise under preparation for the next Fall course on Data Structures and Algorithms. Probably this is just a demo or something students may take a look at, not a required task. &hellip; <a href=\"https:\/\/www.juustila.com\/antti\/2022\/05\/12\/coverage-fight\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Coverage fight&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[2],"tags":[86,77,15,85],"class_list":["post-889","post","type-post","status-publish","format-standard","hentry","category-coding","tag-code-coverage","tag-java","tag-testing","tag-visual-studio-code"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/comments?post=889"}],"version-history":[{"count":3,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/889\/revisions"}],"predecessor-version":[{"id":893,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/posts\/889\/revisions\/893"}],"wp:attachment":[{"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/media?parent=889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/categories?post=889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.juustila.com\/antti\/wp-json\/wp\/v2\/tags?post=889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}