June 23rd, 2024

Getting 100% code coverage doesn't eliminate bugs

Achieving 100% code coverage doesn't ensure bug-free software. A blog post illustrates this with a critical bug missed despite full coverage, leading to a rocket explosion. It suggests alternative approaches and a 20% coverage minimum.

Read original articleLink Icon
Getting 100% code coverage doesn't eliminate bugs

Achieving 100% code coverage does not guarantee bug-free software, as demonstrated by a one-line code example provided in a blog post. The post emphasizes that while some may believe 100% coverage is the ultimate goal for bug elimination, it is not a reliable indicator of software quality. The example highlights a scenario where despite achieving full code coverage and extensive testing, a critical bug causing a divide-by-zero error went unnoticed until a rocket launch resulted in an explosion. The author argues that focusing solely on increasing code coverage to reduce bugs is a misconception and suggests considering alternative approaches like formal verification and proof checkers for mission-critical software. Additionally, the post recommends aiming for a minimum code coverage of 20% based on the Pareto Principle, which suggests that a small portion of code is responsible for the majority of bugs. Junior developers and misguided team managers are mentioned as potential audiences who may benefit from understanding the limitations of code coverage as a metric for software quality.

Link Icon 8 comments
By @turtleyacht - 4 months
Mutation testing with Java pitest measures three things: line coverage, mutation coverage, and test strength.

Jacoco measures both line and branch coverage, same as Jest.

Preferred thing to do is establish a baseline, and then

* Write tests for new features going forward.

* Write tests for fixes to production incidents.

Don't let things get worse than baseline. (The number will vary from repo to repo.)

By @drewcoo - 4 months
Getting <100% coverage means you have no idea what some of the code does when run in dumb, non-parallel mode. Thar be bugs!

And those bugs are easier to find than the ones that might still exist if you have 100% coverage.

No one ever anywhere (except for numerous strawmen) has claimed 100% coverage "will eliminate all bugs and produce the perfect software."

> This article is useless. Everybody knows that 100% code coverage doesn’t eliminate bugs.

A double-secret strawman is still a strawman, dude.

> Junior developers certainly don’t know this. Misguided team managers don’t know it as well.

Great. Do they read your clickbait? If so, do they believe it (on authority, I guess)? Because unless they do, you're certainly a problem and not part of a solution.

By @sebazzz - 4 months
Code coverage only tells if a line or statement was hit. I’ve been working with offshore development teams which get sufficient code coverage, but don’t have any asserts. They call the code, but the test doesn’t test (except maybe a “smoke test” - it doesn’t throw an exception).
By @peter-m80 - 4 months
No, but it helps.

Like money doesn't give happiness... but it helps.

By @ErikBjare - 4 months
When reading the title, the first thing that struck me too was division by zero.

I doubt this is a common misunderstanding among any but the most junior of devs.

By @KevinMS - 4 months
Tomorrow I'm going to ask my scrum master if this is really true.
By @BobbyTables2 - 4 months
News at 11!