Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch coverage incorrect when using elvis operator #729

Open
driessamyn opened this issue Jan 29, 2025 · 0 comments
Open

Branch coverage incorrect when using elvis operator #729

driessamyn opened this issue Jan 29, 2025 · 0 comments
Assignees
Labels
Bug Bug issue type Check In JaCoCo S: postponed Status: work on the issue is not in the short term plans

Comments

@driessamyn
Copy link

Kover incorrectly reports a gap in branch coverage

Consider this class:

class KoverExample {
    private val map = mapOf<Int, () -> String>(
        1 to { "Fred" },
        2 to { "Joe" }
    )
    fun greeting(i: Int): String =
        map[i]
            ?.invoke()
            ?: throw IllegalStateException("No greeting for $i")
}

and these tests:

class KoverExampleTest {
    val koverExample = KoverExample()

    @Test
    fun `when index exists, greet`() {
        koverExample.greeting(1) shouldBe "Fred"
    }

    @Test
    fun `when index does not exist, throw`() {
        shouldThrow<IllegalStateException> {
            koverExample.greeting(-1)
        }
    }
}

Kover reports only 75% branch coverage, highlighting map[i] as not covered.

Expected behavior

Kover should report full coverage in this example, in my opinion, given there is no code path not exercised with the test.

Reproducer

See code above.

Reports

Image

Environment

  • Kover Gradle Plugin version: 0.9.1
  • Gradle version: 8.12
  • Kotlin project type: Kotlin/JVM
  • Coverage Toolset (if customized in build script): Kove
@driessamyn driessamyn added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Jan 29, 2025
@shanshin shanshin added S: postponed Status: work on the issue is not in the short term plans Check In JaCoCo and removed S: untriaged Status: issue reported but unprocessed labels Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type Check In JaCoCo S: postponed Status: work on the issue is not in the short term plans
Projects
None yet
Development

No branches or pull requests

2 participants