# Code Coverage showing 0 for some files

**URL:** <https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084>\
**Category:** SonarQube Server / Community Build\
**Tags:** jacoco, coverage\
**Created:** [September 23, 2024, 8:07am UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084 "2024-09-23T08:07:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankitthakkar](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ankitthakkar](https://community.sonarsource.com/u/ankitthakkar)\
**Post date:** [September 23, 2024, 8:07am UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/1 "2024-09-23T08:07:32Z")

</div>

I’m facing code coverage issues with Hybris ANT. I’m performing the following steps:

1. Created the `jacoco.exec` file using `jacocoagent.jar`.
2. Generated the `jacoco.xml` report using the `jacoco.exec` file created in step 1.
3. Ran the SonarQube scanner and passed the `sonar.coverage.jacoco.xmlReportPaths` property.

Initially, I obtained some coverage, but after adding more unit tests to increase coverage, I see 0% coverage for specific extensions/files.

Here’s how I’m generating the `jacoco.exec` file:

`ant unittests -Dtestclasses.extensions=ext1 -Dtestclasses.reportdir=/tmp/unittests '-Dstandalone.javaoptions=-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoagent.jar=destfile=/tmp/jacoco.exec'`

And here’s how I’m generating the `jacoco.xml` report file from the `jacoco.exec` file:

`java -jar /tmp/jacococli.jar report /tmp/jacoco.exec --classfiles <path/to/classfiles> --xml /tmp/jacoco.xml`

I’m using SonarQube Developer Edition v10.5.1.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [September 24, 2024, 6:42am UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/2 "2024-09-24T06:42:10Z")

</div>

Hey there.

> [@ankitthakkar](#):
>
> /tmp/jacoco.xml

Have you confirmed that this report actually shows coverage on the files you expect to see increased coverage for? SonarQube only reads the report – so if the file isn’t represented in the report or the report says there’s no coverage… SonarQube will believe it.

---

<div class="post-metadata">

**Author:** ![ankitthakkar](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ankitthakkar](https://community.sonarsource.com/u/ankitthakkar)\
**Post date:** [September 24, 2024, 11:31am UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/3 "2024-09-24T11:31:46Z")

</div>

Yes, SonarQube reads coverage from the `/tmp/jacoco.xml` file only. However, when I add new test cases, SonarQube does not show the coverage. I’ve also noticed that sometimes it shows coverage for a specific file, while other times it does not.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [September 24, 2024, 2:56pm UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/4 "2024-09-24T14:56:03Z")

</div>

I understand, but have you actually opened the `/tmp/jacoco.xml` to validate that the new coverage is being reflected in that file?

---

<div class="post-metadata">

**Author:** ![ankitthakkar](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@ankitthakkar](https://community.sonarsource.com/u/ankitthakkar)\
**Post date:** [September 25, 2024, 3:55am UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/5 "2024-09-25T03:55:05Z")

</div>

I can see new methods but it showing covered=“0”.

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [September 25, 2024, 2:43pm UTC](https://community.sonarsource.com/t/code-coverage-showing-0-for-some-files/126084/6 "2024-09-25T14:43:29Z")

</div>

In that case, you’ll have to resolve that issue with your coverage report. SonarQube is just believing the data it is being given in the report.
