# Unable to get code coverage from UI test cases for android (kotlin) project in sonar cloud

**URL:** <https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759>\
**Category:** SonarQube Cloud\
**Tags:** kotlin, coverage, sonarqube-cloud\
**Created:** [November 21, 2023, 1:15pm UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759 "2023-11-21T13:15:47Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rohith0003](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rohith0003](https://community.sonarsource.com/u/rohith0003)\
**Post date:** [November 21, 2023, 1:15pm UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/1 "2023-11-21T13:15:47Z")

</div>

Hi,

There are UI test cases for android project in app/src folder but the number of lines are analyzed and showing as uncovered with 0.0% coverage on the folder.

Any suggestion on the existing issue would be helpful.

Thanks.

---

<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:** [November 23, 2023, 7:39am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/2 "2023-11-23T07:39:13Z")

</div>

Hey there.

Do you actually run the tests as a part of your build, before the SonarCloud analysis?

---

<div class="post-metadata">

**Author:** ![rohith0003](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rohith0003](https://community.sonarsource.com/u/rohith0003)\
**Post date:** [November 23, 2023, 7:54am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/3 "2023-11-23T07:54:03Z")

</div>

Hi @Colin ,

Yes we execute the tests before the sonar cloud analysis task.

Below are the steps we are using in the pipeline:

1. Prepare sonar analysis
2. gradlew test
3. publish code coverage (for the pipeline)
4. Sonar run code analysis
5. publish quality gate results

Please let me know if you need additional information.

Thanks.

---

<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:** [November 28, 2023, 10:49am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/4 "2023-11-28T10:49:18Z")

</div>

Thanks.

Have you [configured the JaCoCo report to export XML reports](https://docs.sonarsource.com/sonarcloud/enriching/test-coverage/java-test-coverage/#adding-coverage-in-a-gradle-project)?

What do the logs say about the import of code coverage?

> [@How to find logs about importing code coverage](https://community.sonarsource.com/t/how-to-find-logs-about-importing-code-coverage/73317):
>
> When coverage data isn’t appearing as expected in SonarQube Server / Community Build or SonarQube Cloud, the first place you should look is the scanner logs. Where do I find the scanner logs?warning This will likely be broken out into its own guide soon The Scanner logs are the output of executing one of the [scanners](https://docs.sonarqube.org/latest/analysis/overview/), either directly or wrapped by one of many integrations, such as the [SonarScanner for Jenkins](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-jenkins/), [SonarScanner for Azure DevOps](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-azure-devops/), [SonarQube](https://github.com/SonarSource/sonarqube-scan-action)/[SonarCloud](https://github.com/marketplace/actions/sonarcloud-scan) GitHub Actions or [SonarQube](https://bitbucket.org/sonarsource/sonarqube-scan/src/master/) /…

---

<div class="post-metadata">

**Author:** ![rohith0003](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rohith0003](https://community.sonarsource.com/u/rohith0003)\
**Post date:** [November 28, 2023, 11:14am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/5 "2023-11-28T11:14:00Z")

</div>

Hi @Colin ,

I notice the jacoco configuration is configured using jacoco.gradle file in repository and i don’t see any config in the build.gradle, could you please confirm is this mandatory to use this in the build.gradle accordingly will request developers to make the changes.

Waiting on your response.

Thanks.

---

<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:** [November 29, 2023, 3:09pm UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/6 "2023-11-29T15:09:02Z")

</div>

It’s not strict that the configuration needs to be in a _build.gradle_ file, but you must be outputting a JaCoCo XML report (and if not to the default location, then that location should be defined using `sonar.coverage.jacoco.xmlReportPaths` as documented).

---

<div class="post-metadata">

**Author:** ![rohith0003](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rohith0003](https://community.sonarsource.com/u/rohith0003)\
**Post date:** [November 29, 2023, 5:28pm UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/7 "2023-11-29T17:28:18Z")

</div>

Yes we are getting the reports to the default path but the UI test cases aren’t calculating over there.

---

<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:** [December 6, 2023, 8:58am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/8 "2023-12-06T08:58:24Z")

</div>

So _some_ coverage is being reported to SonarCloud, but not all? It sounds like an issue with generating the coverage reports to include coverage from the UI test cases, not an issue with SonarCloud reading the report.

---

<div class="post-metadata">

**Author:** ![rohith0003](https://avatars.discourse-cdn.com/v4/letter/r/8e8cbc/32.png) [@rohith0003](https://community.sonarsource.com/u/rohith0003)\
**Post date:** [December 6, 2023, 9:48am UTC](https://community.sonarsource.com/t/unable-to-get-code-coverage-from-ui-test-cases-for-android-kotlin-project-in-sonar-cloud/104759/9 "2023-12-06T09:48:05Z")

</div>

Yes we are only seeing the code coverage from projfolder/main/java folder not form the other folder where the UI test cases exists.
