Skip to content

Extra branches in the when statement #774

@ExFaust

Description

@ExFaust

When using when, there are always extra branches that prevent you from achieving 100% coverage.

Example 1:

private fun replaceGuid(guid: String): String {
        return when (guid) {
            "11" -> "11"
            "22" -> "22"
            "33" -> "33"
            else -> guid
        }
    }

Intellij Coverage Plugin and Kover show 9 branches.

Example 2:

private fun replaceGuid(guid: String): String {
        if (guid == "11"){
            return "11"
        }
        if (guid == "22"){
            return "22"
        }
        if (guid == "33"){
            return "33"
        }
        return guid
    }

Intellij Coverage Plugin and Kover show 4 branches.

Is there any way to fix this without changing the code of the class being tested or modifying the bytecode?

Metadata

Metadata

Assignees

Labels

QuestionSupport request issue typeS: waiting for clarificationStatus: additional information required to proceed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions