

High Code Coverage is not Wasted Effort
source link: https://mechanicalrock.github.io/2018/01/08/high-code-coverage-is-not-yak-shaving.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

High Code Coverage is not Wasted Effort
Jan 8, 2018 • Tim Myerscough
Tags: quality bddRecently, someone asked me what I think about code coverage metrics. They said aiming for 100% code coverage could be considered a waste of effort - since you get diminishing returns.
However, in my opinion, if you hold that view, then you misunderstand what the metric means. You probably either don’t write code, or write crappy code. Code coverage is a metric. It is an indicator about quality. But does not itself guarantee quality.
Code coverage is the percentage of lines of code executed during testing. It’s a technical metric to help understand where your risk lies.
If your code coverage metric is 20%, I don’t know how good your code is. If I had to guess, I’d say “probably bad”. I would lack confidence in touching it. Which will lead to technical debt. You won’t have confidence to repay the debt, since you don’t know if you’ve broken anything. I’d be confident in saying that your code will be crappy in 6-12 months time.
If your code coverage is at 100%, I don’t know how good your code is. If I had to guess, I’d say “probably good”. I would have confidence in changing it and eliminating technical debt. If the windows remained intact, then in 6-12 months time, I’d be confident in saying that it’s much higher quality than the 20% code.
But that still doesn’t tell the whole story. It’s a metric. An indicator. You need to read the story behind the headline. A team that is rewarded by achieving high code coverage, or punished by low coverage, will game the system. Writing pointless, or ineffective, tests in order to push up the stats.
A team with 100% code coverage isn’t unnecessarily wasting effort. Disciplined TDD practitioners know exactly what their code currently does (and does not) do. They have made a decision on the functionality that the code shall demonstrably support. And there is no extraneous code. It does nothing more than it is designed to do. That doesn’t mean that there are no limitations. The code may do no error handling and only cover the happy path. That wasn’t an omission - it’s a conscious decision. It’s not currently supported. We haven’t got to it yet. It’s MVP.
Code can have 100% coverage and just do the wrong thing.
In order to understand the story behind the metric, then you need to take the time to understand the situation. To understand the quality of an application - you need to look at the code. In order to understand the effort that’s gone into writing it - then ask the author.
“Code comments are a source of mis-information” - Clean Code - Robert C. Martin
I say:
“Untested code is a source of unnecessary risk”. Tim Myerscough
You should probably reduce the risk by just deleting it.
Recommend
-
126
The Linux Scheduler: a Decade of Wasted Cores - Lozi et al. 2016 This is the first in a series of papers from EuroSys 2016. There are three strands here: first of all, there's some great background into how scheduling works in the Linux kernel;...
-
108
Post with 1517 votes and 1019077 views. Shared by donthitsave. Don't Hit Save - Wasted Time
-
45
Rough IMHO as of 2019-02-05 There are far too many distributions and desktop environments. So much time and effort goes into developing, establishing, hosting, updating, maintaining, advertising Linux di...
-
6
The UK Has Wasted 50 Years Fighting a Losing War on DrugsOn the 50th anniversary of the Misuse of Drugs Act, VICE World News analysis shows just how catastrophically it has failed.May 26, 2021,...
-
6
June 1, 2021 ...
-
7
September 21, 2021
-
6
Craig Williams is a Comedian and the Curator of Your Wasted TimeSeptember 24th 2021 new story5Cr...
-
9
Network Automation ...
-
7
Avoiding the Pitfalls of Unit Test High Code Coverage With TDDAvoiding the Pitfalls of Unit Test High Code Coverage With TDDFebruary...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK