# Virtual Device Testing: gathering code coverage for reporting to SonarQube fails

**URL:** <https://discuss.bitrise.io/t/virtual-device-testing-gathering-code-coverage-for-reporting-to-sonarqube-fails/12342>\
**Category:** Tooling Issues\
**Created:** [March 22, 2020, 9:02am UTC](https://discuss.bitrise.io/t/virtual-device-testing-gathering-code-coverage-for-reporting-to-sonarqube-fails/12342 "2020-03-22T09:02:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![b.kopiske](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/b.kopiske/32/2822_2.png) [@b.kopiske](https://discuss.bitrise.io/u/b.kopiske)\
**Post date:** [March 22, 2020, 9:02am UTC](https://discuss.bitrise.io/t/virtual-device-testing-gathering-code-coverage-for-reporting-to-sonarqube-fails/12342/1 "2020-03-22T09:02:49Z")

</div>

## Description of the issue

I’ve created a `jacocoTestReport` and a `sonarqube` gradle task in my Android project. I can execute them locally on my machine and push a combined coverage report for the complete test suite, i.e. unit-, robolectric- and instrumented tests. The instrumented tests run on a locally spawned Android emulator. The psuh to SonarQube is successful and includes the complete coverage report.

When trying to execute the sequence `jacocoTestReport` and `sonarqube` on Bitrise, I end up with empty code coverage information on SonarQube. This is most certainly related to the following error I see in the logs:

```auto
Report doesn't exist: '/bitrise/src/app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml'

```

I need to upload the xml report to SonarQube, since the latest versions reject ec/exec files due to their proprietary format.

My `jacocoTestReport` step most likely fails because it does not find the ec files from the instrumented tests – although I wonder why not least the exec file generated by the unit tests is used.

Since I am aware that the Virtual Device Testing step runs the tests on Firebase Test Labs, I guessed that the problem must be related to the ec files not being transferred back to the Bitrise VM. I found someone who claims to have solved this here: [Bitrise configuration + Jacoco for Junit + Instrumentation tests + Vitual Device Testing · GitHub](https://gist.github.com/hernandazevedo/4c19558db2f138c99e3c24838cccf307)

So I tried using the environment variables `coverage=true` and `coverageFile=/sdcard/coverage.ec` for Firebase Test Labs, and adjusted my gradle files to look in the `VDTESTING_DOWNLOADED_FILES_DIR` directory, but without success. I found indications that I should better use `coverageFilePath=/sdcard/` since the location might differ. But that did not work out either.

In the test run logs I found jacoco errors complaining about not having write access. According to [java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system) (again, with solution) · Issue #968 · jacoco/jacoco · GitHub](https://github.com/jacoco/jacoco/issues/968) I created a `jacoco-agent.properties` with `output=none` to avoid fallbacks. But no luck, still no coverage files in the downloaded testing dir – only logcat-dumps, mp4 videos of the testing process, ogg sound recordings, some testsuite xmls (nothing jacoco related) and some other result/summary files (nothing jacoco related).

Here’s the current configuration I’'m using:

jacoco Gradle:

```auto
apply plugin: 'jacoco'

jacoco {
	toolVersion "0.8.5"
}

task jacocoTestReport(type: JacocoReport, dependsOn: "test${coverageFlavor}DebugUnitTest") {

	group = "Reporting"
	description = "Generate Jacoco coverage reports"

	reports {
		xml.enabled = true
		html.enabled = true
	}

	def fileFilter = [
		'**/R.class',
		'**/R$*.class',
		'**/BuildConfig.*',
		'**/Manifest*.*',
		'android/**/*.*',
		'**/Lambda$*.class',
		'**/Lambda.class',
		'**/*Lambda.class',
		'**/*Lambda*.class',
		'**/*Lambda*.*',
		'**/*Builder.*',
		'**/*_MembersInjector.class',
		'**/*_MembersInjector*.*',
		'**/*_*Factory*.*',
		'**/*Component*.*',
		'**/*Module*.*'
	]
	def debugTree = fileTree(dir: "${buildDir}/intermediates/app_classes/${coverageFlavor}Debug", excludes: fileFilter)
	def mainSrc = "${project.projectDir}/src/main/java"

	getSourceDirectories().setFrom(files([mainSrc]))
	getClassDirectories().setFrom(files([debugTree]))
	getExecutionData().setFrom(
		[fileTree(dir: project.buildDir, includes: [
			'jacoco/test${coverageFlavor}DebugUnitTest.exec',
			'outputs/code_coverage/${coverageFlavor}DebugAndroidTest/**/*.ec'
		])],
		[fileTree(dir: "${System.env.VDTESTING_DOWNLOADED_FILES_DIR}", includes: [
			'*.ec'
		])])
}

```

bitrise.yml [VDT step]

```auto
    - virtual-device-testing-for-android:
        inputs:
        - environment_variables: |-
            coverage=true
            coverageFilePath=/sdcard/
        - directories_to_pull: "/sdcard/"
        - download_test_results: 'true'
        - use_verbose_log: 'true'
        - test_type: instrumentation
        - inst_use_orchestrator: 'true'
        - test_devices: |-
            Pixel2,28,en,portrait
            Nexus6P,27,en,portrait
        - num_flaky_test_attempts: '1'

```

What am I doing wrong?

## Environment:

Android & Docker, on Ubuntu 16.04

Involved steps: Virtual Device Testing / Gradle Tasks for `jacocoTestReport` and `sonarqube`

## Reproducibility

- the issue happens all the time
- the issue was there from beginning
- all steps are used in the latest version

## Build log

[https://app.bitrise.io/build/3a5ac8e41f77046f#?tab=log](https://app.bitrise.io/build/3a5ac8e41f77046f#?tab=log)

---

<div class="post-metadata">

**Author:** ![non-binary](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/non-binary/32/2764_2.png) [@non-binary](https://discuss.bitrise.io/u/non-binary)\
**Post date:** [April 20, 2020, 1:20pm UTC](https://discuss.bitrise.io/t/virtual-device-testing-gathering-code-coverage-for-reporting-to-sonarqube-fails/12342/2 "2020-04-20T13:20:46Z")

</div>

Reach out to us via [https://www.bitrise.io/bitrise-support](https://www.bitrise.io/bitrise-support). You will receive an answer much faster through email support than the forum.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/d/d901cf2aad020f2dd11918afc89ec2089bb87b35.png) [@system](https://discuss.bitrise.io/u/system)\
**Post date:** [May 20, 2020, 1:20pm UTC](https://discuss.bitrise.io/t/virtual-device-testing-gathering-code-coverage-for-reporting-to-sonarqube-fails/12342/3 "2020-05-20T13:20:49Z")

</div>

Closed on May 20, 2020, 1:20pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
