by kccqzy · 2y ago · 0 comments
I'm going to disagree respectfully here. I don't think hard-and-fast rules on code coverage are useful (e.g. must achieve 90% coverage before merging), but just having code coverage run automatically and its results displayed is useful. When I add an "if" check and one of the branches isn't covered for example, I start to think what if some junior engineer didn't understand the reason behind this "if" check and decided to delete this check altogether? If no unit tests fail after deleting this check, that junior engineer might not have enough context to judge whether this check is needed in production.
I think the real takeaway here is that code quality doesn't really matter. The most horribly written code is still quite fine to work with if well documented.
/* BadImpl.java */
if (theFile.exists()) {
doTheAwesome(theFile);
}
// uh, and else ... what?
/* BadImplTest.java */
@Test
public void looksGoodTestCoverage() {
theFile.create();
instance.runIt();
println("hurray, 100% coverage");
}
versus if the coverage tool was able to artificially rewrite the code to be this way, it would show up as not covered: if (theFile.exists()) {
...
} else {
}