Loading...
Loading...
JaCoCo Java code coverage tool USE WHEN: user mentions "JaCoCo", "Java coverage", "code coverage", asks about "coverage threshold", "jacoco-maven-plugin", "coverage report", "LINE coverage", "BRANCH coverage" DO NOT USE FOR: JavaScript/TypeScript coverage - use Vitest skill, SonarQube analysis - use `sonarqube` skill, test execution - use testing skills
npx skill4agent add claude-dev-suite/claude-dev-suite jacocosonarqubeDeep Knowledge: Usewith technology:mcp__documentation__fetch_docsfor comprehensive documentation.jacoco
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals><goal>report</goal></goals>
</execution>
<execution>
<id>check</id>
<goals><goal>check</goal></goals>
<configuration>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.80</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin><excludes>
<exclude>com.company.config.*</exclude>
<exclude>com.company.dto.*</exclude>
<exclude>com.company.entity.*</exclude>
<exclude>com.company.mapper.*Impl</exclude>
</excludes>mvn clean verify # Test + coverage check
mvn jacoco:report # Generate report
open target/site/jacoco/index.html # View report| Counter | Description |
|---|---|
| Lines of code |
| Branch if/switch |
| Methods |
| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| Aiming for 100% coverage | Diminishing returns, test bloat | Target 80% LINE, 70% BRANCH |
| Including DTOs/entities in coverage | Inflates numbers, no logic to test | Exclude with |
| Only checking LINE coverage | Misses untested branches | Check both LINE and BRANCH |
| No coverage threshold in CI | Can't enforce quality | Add |
| Excluding too much code | False sense of security | Only exclude generated/config code |
| Not versioning jacoco.exec | Can't track coverage trends | Archive reports in CI |
| Issue | Likely Cause | Solution |
|---|---|---|
| Coverage report shows 0% | Tests not running with agent | Ensure |
| Build fails on coverage check | Coverage below threshold | Add tests or adjust minimum in |
| Report excludes nothing | Wrong exclude pattern | Use fully qualified names (com.company.dto.*) |
| Report missing classes | Classes not loaded during tests | Add integration tests to cover them |
| Coverage lower in CI than local | Different test execution | Ensure CI runs all test phases |
| SonarQube shows no coverage | Wrong report path | Check |
For advanced configurations:mcp__documentation__fetch_docs
- Technology:
(not yet in MCP - use official docs)jacoco- JaCoCo Docs