<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Meltem Aşkın on Medium]]></title>
        <description><![CDATA[Stories by Meltem Aşkın on Medium]]></description>
        <link>https://medium.com/@meltemaskin?source=rss-f3bca22ac331------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Meltem Aşkın on Medium</title>
            <link>https://medium.com/@meltemaskin?source=rss-f3bca22ac331------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:19:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meltemaskin/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ Test Coverage Management in Java: JaCoCo Integration in Single & Multi-Module Maven Projects]]></title>
            <link>https://medium.com/@meltemaskin/test-coverage-management-in-java-jacoco-integration-in-single-multi-module-maven-projects-cb70bbc92560?source=rss-f3bca22ac331------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb70bbc92560</guid>
            <dc:creator><![CDATA[Meltem Aşkın]]></dc:creator>
            <pubDate>Wed, 10 Dec 2025 14:37:01 GMT</pubDate>
            <atom:updated>2025-12-10T14:37:01.604Z</atom:updated>
            <content:encoded><![CDATA[<p>Automated testing is a fundamental pillar of sustainable software quality.<br>However, having tests alone is not enough — we must also measure <strong>how much of the codebase is being exercised</strong>.</p><p>In the Java ecosystem, <strong>JaCoCo</strong> is one of the most widely used tools for measuring code coverage.</p><p>This article walks you step-by-step through how to integrate JaCoCo into both <strong>single-module</strong> and <strong>multi-module</strong> Maven projects.</p><p><strong>📝 TL;DR</strong></p><ul><li>✅ <strong>Single-module </strong>JaCoCo setup is straightforward.</li><li>🧩 <strong>Multi-module </strong>projects require <strong>merging (aggregate)</strong> report output.</li><li>📈 <strong>Coverage should be generated in XML</strong> format to be consumed by SonarQube.</li><li>🚦 <strong>Adding coverage thresholds into CI/CD</strong> helps maintain consistent quality standards.</li></ul><p><strong>🧪 1. What is JaCoCo?</strong></p><p>JaCoCo (Java Code Coverage) monitors test execution and reports which lines and branches of code were executed.</p><p><strong>Benefits include:</strong></p><ul><li>Strong integration with Maven and Gradle</li><li>HTML, XML, and CSV coverage reporting</li><li>Line/branch coverage insights</li><li>Compatibility with CI/CD and quality platforms (e.g., SonarQube)</li></ul><p><strong>🧭 2. JaCoCo in Single-Module Maven Projects</strong></p><p>Setting up JaCoCo in a single-module Maven project is simple. The following example shows the basic configuration for a Maven project.</p><p><strong>📄 pom.xml configuration</strong></p><pre>&lt;build&gt;<br>  &lt;plugins&gt;<br>    &lt;!-- JaCoCo Agent --&gt;<br>    &lt;plugin&gt;<br>      &lt;groupId&gt;org.jacoco&lt;/groupId&gt;<br>      &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;<br>      &lt;version&gt;0.8.11&lt;/version&gt;<br>      &lt;executions&gt;<br>        &lt;execution&gt;<br>          &lt;id&gt;prepare-agent&lt;/id&gt;<br>          &lt;goals&gt;&lt;goal&gt;prepare-agent&lt;/goal&gt;&lt;/goals&gt;<br>          &lt;configuration&gt;<br>            &lt;propertyName&gt;jacoco.argLine&lt;/propertyName&gt;<br>          &lt;/configuration&gt;<br>        &lt;/execution&gt;<br>        &lt;execution&gt;<br>          &lt;id&gt;report&lt;/id&gt;<br>          &lt;phase&gt;test&lt;/phase&gt;<br>          &lt;goals&gt;&lt;goal&gt;report&lt;/goal&gt;&lt;/goals&gt;<br>        &lt;/execution&gt;<br>        &lt;!-- Coverage threshold control --&gt;<br>        &lt;execution&gt;<br>          &lt;id&gt;check&lt;/id&gt;<br>          &lt;goals&gt;&lt;goal&gt;check&lt;/goal&gt;&lt;/goals&gt;<br>          &lt;configuration&gt;<br>            &lt;rules&gt;<br>              &lt;rule&gt;<br>                &lt;element&gt;BUNDLE&lt;/element&gt;<br>                &lt;limits&gt;<br>                  &lt;limit&gt;<br>                    &lt;counter&gt;LINE&lt;/counter&gt;<br>                    &lt;value&gt;COVEREDRATIO&lt;/value&gt;<br>                    &lt;minimum&gt;0.80&lt;/minimum&gt;<br>                  &lt;/limit&gt;<br>                &lt;/limits&gt;<br>              &lt;/rule&gt;<br>            &lt;/rules&gt;<br>          &lt;/configuration&gt;<br>        &lt;/execution&gt;<br>      &lt;/executions&gt;<br>    &lt;/plugin&gt;<br>    <br>    &lt;!-- Surefire plugin --&gt;<br>    &lt;plugin&gt;<br>      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;<br>      &lt;version&gt;3.2.5&lt;/version&gt;<br>      &lt;configuration&gt;<br>        &lt;argLine&gt;${jacoco.argLine}&lt;/argLine&gt;<br>      &lt;/configuration&gt;<br>    &lt;/plugin&gt;<br>  &lt;/plugins&gt;<br>&lt;/build&gt;</pre><p>👉 Command:</p><pre>mvn clean verify</pre><p>📊 Reports:</p><ul><li><strong>HTML:</strong> target/site/jacoco/index.html</li><li><strong>XML:</strong> target/site/jacoco/jacoco.xml</li></ul><p>This XML file is used to provide coverage reports to SonarQube or similar tools.</p><p><strong>🧩 3. JaCoCo in Multi-Module Maven Projects</strong></p><p>In multi-module builds, each module produces its own coverage report.<br>To get a <strong>true overall coverage</strong>, reports must be <strong>merged (aggregated)</strong>. Otherwise, quality tools cannot accurately calculate total coverage.</p><p>No aggregation = misleading metrics.</p><p><strong>⚠️ Key Principles</strong></p><ul><li>Prepare-agent must be running in every module.</li><li>Report integration should only be done via the root or a dedicated reporting module.</li><li>The XML report path must be compatible with SonarQube (sonar.coverage.jacoco.xmlReportPaths).</li></ul><p><strong>🧱 3.1 Sub-Module Configuration</strong></p><p>The following structure should be added to the pom.xml file of each submodule:</p><pre>&lt;plugin&gt;<br>  &lt;groupId&gt;org.jacoco&lt;/groupId&gt;<br>  &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;<br>  &lt;version&gt;0.8.11&lt;/version&gt;<br>  &lt;executions&gt;<br>    &lt;execution&gt;<br>      &lt;id&gt;prepare-agent&lt;/id&gt;<br>      &lt;goals&gt;&lt;goal&gt;prepare-agent&lt;/goal&gt;&lt;/goals&gt;<br>    &lt;/execution&gt;<br>    &lt;execution&gt;<br>      &lt;id&gt;report&lt;/id&gt;<br>      &lt;phase&gt;verify&lt;/phase&gt;<br>      &lt;goals&gt;&lt;goal&gt;report&lt;/goal&gt;&lt;/goals&gt;<br>    &lt;/execution&gt;<br>  &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><p>And:</p><pre>&lt;plugin&gt;<br>  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;<br>  &lt;version&gt;3.2.5&lt;/version&gt;<br>  &lt;configuration&gt;<br>    &lt;argLine&gt;${jacoco.argLine}&lt;/argLine&gt;<br>  &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p><strong>📊 3.2 Merging Coverage (Aggregation)</strong></p><p>The main module (or a special “coverage-report” module) collects the jacoco.exec files from all modules to create a combined report.</p><pre>&lt;plugin&gt;<br>  &lt;groupId&gt;org.jacoco&lt;/groupId&gt;<br>  &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;<br>  &lt;version&gt;0.8.11&lt;/version&gt;<br>  &lt;executions&gt;<br>    &lt;execution&gt;<br>      &lt;id&gt;report-aggregate&lt;/id&gt;<br>      &lt;phase&gt;verify&lt;/phase&gt;<br>      &lt;goals&gt;&lt;goal&gt;report-aggregate&lt;/goal&gt;&lt;/goals&gt;<br>    &lt;/execution&gt;<br>  &lt;/executions&gt;<br>&lt;/plugin&gt;</pre><p>👉 Command:</p><pre>mvn clean verify</pre><p>📈 Report Outputs:</p><ul><li><strong>HTML:</strong> target/site/jacoco-aggregate/index.html</li><li><strong>XML:</strong> target/site/jacoco-aggregate/jacoco.xml</li></ul><p><strong>🧭 4. Pipeline Flow</strong></p><p>The following image shows how the coverage collection process is positioned within CI/CD:</p><p>Press enter or click to view image in full size</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*A8mZB1-jLoHbus6U.png" /></figure><p><strong>Steps:</strong></p><ol><li>The developer submits the code.</li><li>CI is triggered, and mvn clean verify is run.</li><li>Tests are run on a module-by-module basis.</li><li>JaCoCo coverage files are created.</li><li>Reports are aggregated.</li><li>SonarQube analysis reads the coverage data.</li></ol><p>The build fails in subthreshold cases.</p><p><strong>🧪 5. Integrating JaCoCo with SonarQube</strong></p><p>If you are using SonarQube or SonarCloud, you need to define the XML report path:</p><pre>mvn clean verify sonar:sonar \<br>  -Dsonar.coverage.jacoco.xmlReportPaths=target/site/jacoco-aggregate/jacoco.xml</pre><p>💡<strong>Note:</strong> The .exec format is no longer supported by Sonar. The XML format is required.</p><p><strong>⚠️ 6. Common Issues &amp; Tips</strong></p><ul><li>❌ <strong>Not aggregating exec files:</strong> Coverage will appear incomplete.</li><li>❌ <strong>Incorrect Sonar path:</strong> SonarQube may not display coverage.</li><li>⚡<strong> Parallel build / forkCount impact:</strong> Coverage file may not be created.</li><li>🧪 <strong>Integration test coverage may be excluded:</strong> merge goal should be used.</li><li>🧼 <strong>Incorrect exclude strategies:</strong> Coverage percentage may be misleading.</li></ul><p><strong>🏁 7. Conclusion</strong></p><ul><li>✅ JaCoCo installation is quick in single-module projects.</li><li>🧩 In multi-module structures, the right report integration strategy directly impacts coverage quality.</li><li>🧪 XML-formatted reports have become the standard for SonarQube.</li><li>🧠 Adding a coverage threshold to the pipeline solidifies a testing culture within the team.</li></ul><p>When configured correctly, JaCoCo becomes a powerful mechanism for <strong>visibility, transparency, and code quality enforcement.</strong></p><p><strong>📚 Resources</strong></p><ul><li>JaCoCo Official Docs</li><li>SonarQube Community</li><li>SonarQube &amp; JaCoCo XML Coverage Guide</li><li>Maven Surefire Plugin</li><li>Maven Failsafe Plugin</li></ul><p>✍️<em> Author: Meltem Aşkın</em><br>Backend Developer | Software Quality Enthusiast ☕💻<br>#Java #JaCoCo #CodeCoverage #SonarQube #Backend #SoftwareQuality #Testing #Maven #DevOps #CI/CD</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb70bbc92560" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>