[Kotlin]Code coverage for local report and codecov are different


I’m having a problem with the output of test code coverage using Spek on Android (Kotlin).
The test code coverage is output using Jacoco, and the code coverage can be confirmed correctly in the output local jacoco report.
However, if you give it to Codecov, the code coverage will be extremely low.

When I checked the Codecov report, I found that only the first line of the test code class declaration turned green and the rest turned red. (See attached image) I’m wondering if Codecov doesn’t recognize Kotlin (Spek) test code well in my settings. Is there any good way to deal with it?

Repository![スクリーンショット 2020-10-22 11.37.35|690x41



Circle CI


bash <(curl -s https://codecov.io/bash) -f ./build/reports/jacoco/jacocoMergedReport/jacocoMergedReport.xml

I’m running this command in config.yml for CircleCI.

Codecov YAML

notify: notify:
	require_ci_to_pass: yes

precision: 2
round: down
range: "70 ... 100"

status: status:
	default: default:
		target: 70%
	patch: no # See: https://docs.codecov.io/docs/commit-status#section-patch-status
	changes: no

	conditional: yes
	loop: yes
	method: no
	macro: no

comment: # See: https://docs.codecov.io/docs/pull-request-comments
layout: "reach, diff, flags, files"
behavior: default
require_changes: no
require_base: yes
require_head: yes

Additional Information

Platform: Android
Language: Kotlin
Test environment: JUnit, Spek

Hi @k-masashi, can you please provide a commit SHA so we can inspect? Also, for the class declaration given, what file is this for?

Hi @tom, Thank you for your reply.

a commit SHA is

The image of the class declaration attached to the question was just an example. Similarly, for other class declarations, only one line of the class declaration will be green and the other lines will be red.

The above declaration is the test code written for the following class.

internal class LogoutUseCaseImpl @Inject constructor(
    private val moveToTrashAllDownloadedCourseService: MoveToTrashAllDownloadedCourseService,
    private val clearTokensService: ClearTokensService,
    private val clearApiDiskCachesService: ClearApiDiskCachesService,
    private val clearApiMemoryCachesService: ClearApiMemoryCachesService,
    private val lastTabIndexPreference: LastTabIndexPreference
) : LogoutUseCase, ClearLocalDataUseCase {
    override fun execute(): Completable =

Hi @k-masashi, please take a look at the raw report in the Build tab. You’ll notice that the coverage shown on Codecov matches what is being inputted (e.g. the lines above are shown as not covered)

<sourcefile name="LogoutUseCaseImplSpec.kt">
   <line nr="18" mi="0" ci="5" mb="0" cb="0" />
   <line nr="20" mi="2" ci="0" mb="0" cb="0" />
   <line nr="21" mi="2" ci="0" mb="0" cb="0" />
   <line nr="22" mi="2" ci="0" mb="0" cb="0" />
   <line nr="23" mi="2" ci="0" mb="0" cb="0" />
   <line nr="24" mi="2" ci="0" mb="0" cb="0" />
   <line nr="25" mi="2" ci="0" mb="0" cb="0" />
   <line nr="26" mi="2" ci="0" mb="0" cb="0" />
   <line nr="27" mi="2" ci="0" mb="0" cb="0" />
   <line nr="28" mi="4" ci="0" mb="0" cb="0" />
   <line nr="30" mi="15" ci="0" mb="0" cb="0" />
   <line nr="31" mi="3" ci="0" mb="0" cb="0" />
   <line nr="32" mi="5" ci="0" mb="0" cb="0" />

This is likely an issue with the way you are collecting coverage or a setting in Kotlin.