I am using Jacoco to check the coverage of my test, i tried lots of way but it still warning 1 of 4 branches missed
fun countingDeleteDemo() : Int {
return list.count { it.isDeleted() }
}
How can I know what branch is missed? I have read some posts about the logic true
&& false
, but is there any documents or official link about the mistake of the coverage tools?
Jacoco checks the code coverage on byte code and not on source code. As far as I know Jacoco does not show which branch is missing.
If you use
IntelliJ IDEA
, you can check the kotlin bytecode.Here, the missing branch in my IDE.
Kotlin's has many builtin extension function
count
forIterable
,Array
...I presume that your
list
is a simpleList
, so an Iterable. You do not have much more elements thanInt.MAX_VALUE
which will make the count negative. But one can pass an iterable which may have beyondInt.MAX_VALUE
elements tocount
.As a good citizen, the kotlin jvm implementation checks count overflow.
You can check out the implementation details.
https://github.com/JetBrains/kotlin/blob/b8ea48fdc29678b6d99cb1b7bad312f917ea9529/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt#L111