android-test icon indicating copy to clipboard operation
android-test copied to clipboard

corrupt jacoco files when test-services is used

Open TZanke opened this issue 2 years ago • 4 comments

Description

Currupt jacoco .ec files with androidx.test.services:test-services

Steps to Reproduce

Create App with tests and start gradle create[abc]AndroidTestCoverageReport

Expected Results

Successful Coverage Report created

Actual Results

Report only runs on fresh/cleared emulators, a second run on the same emulator will fail.

AndroidX Test and Android OS Versions

androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
androidTestUtil 'androidx.test:orchestrator:1.4.1'
androidTestUtil 'androidx.test.services:test-services:1.4.1'

Android Emulator API 29

Link to a public git repo demonstrating the problem:

-private

Gradle:

execution = 'ANDROIDX_TEST_ORCHESTRATOR' testInstrumentationRunnerArguments clearPackageData: 'true' testInstrumentationRunnerArguments useTestStorageService: 'true'

Problem

On first execution of create[abc]AndroidTestCoverageReport a file for each individual test is placed in /storage/emulated/0/googletest/internal_use/data/data/[APPNAME]/coverage_data/ in the format [TestName].ec

The files are then copied to ./app/build/outputs/code_coverage/[abc]AndroidTest/connected/ and the report is generated by jacoco. Works nicely, but:

On second execution of the gradle CoverageReport the .ec files are generated again, BUT the report fails with 'Unable to generate Jacoco report' and additionally 'Unknown block type [...] ' if --info is enabled. Caused by corrupt .ec files on the emulator device itself. After inspecting the old file with the new file it looks like the newly generated file is shorter as the first one, but the size of the file is not changed. So garbage of the first file still exists on the end of the file, breaking jacoco.

First file-ending: internal/SafeCollector_commonKt\80 second file-ending: internal/SafeCollector_commonKt\80riptor$Compani......

Looks strange and broken to me.

Disabling clearPackageData & useTestStorageService will fix the issue, cause the files are created on the Dev Machine, not on the emulator now.

TZanke avatar May 30 '22 14:05 TZanke

Looks like this is related to the implementation of the Android Studio Gradle plugin. Assigning to Yuki to take a look.

adazh avatar May 31 '22 17:05 adazh

Yes, we are aware of this issue and here is our tracking bug: https://issuetracker.google.com/issues/203448784. However, we don't have any progress on it yet.

yuuki3655 avatar May 31 '22 21:05 yuuki3655

@adazh thank you

@yuuki3655 there is also another bug i found in correlation to this one. When renaming a test, then the .ec file of the old name will not disappear on the device. Maybe generating a false report. To fix this issue and the one i described right now, i always delete the contents of /storage/emulated/0/googletest/internal_use/data/data/[APPNAME]/coverage_data/ manually on my dev pc and use the "delete emulator after run" option on jenkins-ci. Maybe, deleting all files / clear the last runs data is a valid approach to fix the issue permanently on google side?

TZanke avatar Jun 01 '22 09:06 TZanke

That sounds like an issue in Android Gradle plugin. I created a separate bug for that, https://issuetracker.google.com/issues/234634397. I'll take a look.

yuuki3655 avatar Jun 01 '22 20:06 yuuki3655

Almost one year without any fix. WTF ?

If you want a reproduction project, here's mine. https://github.com/NinoDLC/OpenClassrooms_P4_MaReu_Example/tree/unified_test_report

The report is correctly generated if you comment the lines :

        testInstrumentationRunnerArguments clearPackageData: 'true'
        testInstrumentationRunnerArguments useTestStorageService: 'true'

NinoDLC avatar Oct 06 '22 09:10 NinoDLC

I suggest following up on the bugs mentioned above, as I think its been established this is a android gradle plugin issue.

brettchabot avatar Oct 06 '22 15:10 brettchabot