Code coverage doesn’t tell you the test quality.

Toomtarm Kung
2 min readMay 29, 2017
http://gazettereview.com

I used to work in a software project. This project had a deadline in a few months later. Besides, the management set the KPI

The minimum code coverage is 70%

They didn’t care about the test quality. They just wanted to see only the report of the code coverage that we have the high percentage. My team had to work under the pressure because the tight deadline, and the non-sense KPI. We had to focus on the code coverage rather than test quality. But

High quality of software = High code coverage,
High code coverage ≠ High quality software.

What does the code coverage exactly tell you? It just tell you that which part of your code that has been executed by the test. It doesn’t tell you that you have the high quality software at all. What if I run the test but I don’t have any assertion?

boolean isTelephoneNumber(String text){
return text.matches("^[\\d]+$");
}
@Test
public void theNumberStringMustPassTheTelephoneNumberValidation(){
String telephoneNumber = "0848327948";
boolean isValid = Validator.isTelephoneNumber(telephoneNumber);
//No Assertion
}

Code coverage in the report is 100%. Management satisfy, nobody cares about this test anymore until you know that the system doesn’t pass QA.

You will see that this test is useless. It doesn’t have any assertion, or even it has, it doesn’t cover the case of hyphen separate (080–144–9489), or country code prefix (+6480–144–9489), and any other cases.

There is one more case, some people implement the end-to-end test. Only 1 test can make 100% code coverage to many classes.

The important thing you should do is to find any way that can break or compromise the logic, then write the test to make it fail, finally write the code to fix it rather than focus on only the coverage number.

--

--