<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Roman Kushnir on Medium]]></title>
        <description><![CDATA[Stories by Roman Kushnir on Medium]]></description>
        <link>https://medium.com/@roman.kushnir?source=rss-172f0ba6e671------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JKiFZyECMtCGqzf-7fEflA.jpeg</url>
            <title>Stories by Roman Kushnir on Medium</title>
            <link>https://medium.com/@roman.kushnir?source=rss-172f0ba6e671------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:44:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@roman.kushnir/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Code Coverage Percentage is an Illusion]]></title>
            <link>https://medium.com/kloeckner-i/code-coverage-percentage-is-an-illusion-7f6066383713?source=rss-172f0ba6e671------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f6066383713</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[best-practices]]></category>
            <category><![CDATA[test-coverage]]></category>
            <category><![CDATA[confidence]]></category>
            <dc:creator><![CDATA[Roman Kushnir]]></dc:creator>
            <pubDate>Wed, 28 Apr 2021 09:39:50 GMT</pubDate>
            <atom:updated>2021-04-28T09:39:50.612Z</atom:updated>
            <content:encoded><![CDATA[<h3>Test Coverage is an Illusion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*PoN814fz2R_VcX53v9g2EQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@clintadair?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Clint Adair</a> on <a href="https://unsplash.com/s/photos/safety-net?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>What’s the coverage that your code coverage tool reports? Is it 90, or 95, or 99.9 percent? Unless it’s 0 or 100 percent I’d say the exact value doesn’t matter. Zero percent coverage doesn’t exactly leave us sleeping well at night, so we’re left with only the latter option.</p><p>To illustrate why 100 percent coverage is the only reasonable choice, let’s consider an extreme example. We get given the task of implementing reporting for an existing project. Before we make any changes, we go to the test folder to make sure there’s a safety net in place. But instead of seeing a test suite we are presented with an ominous todo statement</p><pre>def test_it_works<br> # TODO: add tests later<br> assert(true)<br>end</pre><p>With rolling eyes we close the file and get to work making sure that our new code is properly tested. Our reporting feature exposes many different metrics and for each metric there are correspondingly many lines of calculation code.</p><p>So when we run the updated test suite we’re greeted with an exciting 20 percent coverage. However did the project get any safer with this now much higher coverage value, after all it used to be was zero? No, the main logic of the service still has no coverage.</p><p>Similarly with an opposing example, when we remove an obsolete but well tested feature, the test coverage drops. Does it mean the code is now less safe? It makes no sense. This is especially problematic when there is an enforced coverage threshold in the CI pipeline. When the obsolete code was left in place we were over the required coverage threshold, and when removed we are now below. With a broken build you are put in the position of writing tests for anything you can find, almost always unrelated to the original task.</p><p>So what can we do to make our test suite more honest, transparent, and fair? Let’s simply pull ourselves together and always test every line of code. Sure it’s a noble goal, but it’s probably not realistic. There are sometimes tests which we intentionally want to skip, and there’s legacy code which may not be practical to write tests for.</p><p>Instead I suggest a more pragmatic approach:<br><strong>1. Set the test coverage threshold to 100 percent.<br>2. Wrap all currently untested code with “nocov”.</strong></p><p>This brings about a number of benefits. The coverage no longer drops for unrelated reasons, such as high coverage features being deleted. The nocov comments act as a test coverage map so we can easily see low coverage areas and address them. Missing tests going forwards become intentional rather than accidental, any untested code will result in a broken build.</p><p>When intentionally skipping an area of code, we can only do it with a “nocov”, which makes it visible to the code reviewers and can bring up a discussion about whether it’s justified. The comments can also include context on the reason for the lack of test coverage, and act as a hint for future contributors.</p><p>It’s a small change but with interesting benefits. I was pretty excited to learn about it and hope you find it useful too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f6066383713" width="1" height="1" alt=""><hr><p><a href="https://medium.com/kloeckner-i/code-coverage-percentage-is-an-illusion-7f6066383713">Code Coverage Percentage is an Illusion</a> was originally published in <a href="https://medium.com/kloeckner-i">kloeckner.i</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>