5

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?

Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222

3 Answers3

6

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

Stefan
  • 2,098
  • 2
  • 18
  • 29
3

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

thundear
  • 118
  • 6
0

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() {
}
Jing Ma
  • 183
  • 2
  • 12