6

Based on the release notes in version 0.8.3 the not-null assertion operator is filtered out, I'm using Jacoco version 0.8.5 like this:

jacoco {
    toolVersion = "0.8.5"
}

But it's telling me that Not covered by tests (8 conditions)

Not covered by tests (8 conditions)

I'm using com.dicedmelon.gradle:jacoco-android Github link

I think toolVersion = "0.8.5" not working or something like that, so for that I need a way to force Jacoco version.

Is there any way to fix this issue?

Mohamed Hamdan
  • 147
  • 2
  • 16
  • 2
    The configuration looks right. If you are not sure about which version is running, in the html report, at the bottom right, you can see version used to generate it `Created with JaCoCo 0.8.X`. Have you checked which value is there? Example: https://www.eclemma.org/jacoco/trunk/index.html – rolgalan Jul 25 '20 at 19:13
  • @rolgalan Created with JaCoCo 0.8.5.201910111838 – Mohamed Hamdan Jul 27 '20 at 15:27
  • 1
    Then the jacoco version is being applied properly with the toolVersion setter and the issue is somewhere else. You should share the specific code and tests to evaluate the source of that coverage issue. – rolgalan Jul 27 '20 at 15:50

1 Answers1

1

Without seeing your code and your tests I can't say with 100% confidence but it looks like Jacoco is working fine and there are cases not covered there.

You're using the !! 3 times. When you use this operator, in reality, you're creating 2 flows, for when the variable is null and another for not-null. If you add tests for the cases where the variables are null, you should reach 100% coverage.

Just to make explicit, if you would handle your nullable with safe calls, you would have something like this:

val token = authResult.user?.let {
        authenticationDataSource.getIdToken(true, it)
            ?.let { it.token }
            ?: throw GetIdTokenResultIsNullException()
    } ?: throw UserIsNullException()

    token?.let {
        authenticationDataSource.loginBy(AuthenticationPayload(it))
    } ?: throw TokenIsNullException()

Wherever, I'm throwing exceptions you should handle that case as desired, and this is the alternate branch that is created by the nullability.

If you're sure that your values won't be null then you should change your types to make it clear and avoid extra checks.

On a side note, jacoco-android doesn't seem to be maintained anymore here and it's not compatible with newer gradle versions, so I would recommend using Jacoco directly. Migrating from jacoco-android to jacoco shouldn't be that hard.

a.masri
  • 2,439
  • 1
  • 14
  • 32
Douglas Kazumi
  • 1,206
  • 10
  • 14