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?

3 Answers 3

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

Well okay, and how does one tests a static method with coverage?
3

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

Comments

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() {
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.