Class name is marked as 'not covered' while running code coverage in Android Studio
Asked Answered
T

3

7

I have tried AndroidStudio's code coverage feature and I have met a strange issue:

It is marks the tested class's name as 'not covered' code. How is that possible? Is that a bug?

Picture here:

enter image description here

As you can see it has one method with 4 lines and each one of them is covered. So why is the red line at the class's name?

Tetragrammaton answered 20/2, 2017 at 15:12 Comment(0)
C
6

You are using a static method, so the class itself is never created as an object, therefore never testing that ability.

Christology answered 20/2, 2017 at 15:33 Comment(2)
Well okay, and how does one tests a static method with coverage?Tetragrammaton
#9700679 like thisChristology
C
3

I tried the lombok @UtilityClass, it helped to ignore the class name and code coverage was improved to be 100%.

Chamaeleon answered 16/9, 2020 at 1:7 Comment(0)
B
1

Since also a class with a static function has a default no-argument constructor, your code coverage tool will complain. A good way to solve this, is by adding a private constructor.

private EmailValidator() {
}
Beowulf answered 29/7, 2022 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.