{"path": "/posts/tests-comes-first-coverage-comes/", "title": "Tests comes first; coverage comes way later · Bruno Dias", "html": "<!doctype html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"utf-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <meta name=\"description\" content=\"This should be obvious by now. 100% coverage doesn&#x27;t mean anything, but 0% means a lot.\">\n  <title>Tests comes first; coverage comes way later · Bruno Dias</title>\n  <link rel=\"canonical\" href=\"https://diasbruno.github.io/posts/tests-comes-first-coverage-comes/\" data-post-metadata>\n  <meta name=\"author\" content=\"Bruno Dias\" data-post-metadata>\n  <meta property=\"og:type\" content=\"article\" data-post-metadata>\n  <meta property=\"og:title\" content=\"Tests comes first; coverage comes way later\" data-post-metadata>\n  <meta property=\"og:url\" content=\"https://diasbruno.github.io/posts/tests-comes-first-coverage-comes/\" data-post-metadata>\n  <meta property=\"article:published_time\" content=\"2025-10-29T22:30:48+00:00\" data-post-metadata>\n  <meta property=\"og:image\" content=\"https://diasbruno.github.io/assets/site/substack/tests-comes-first-coverage-comes/figure-1.jpg\" data-post-metadata>\n  <link rel=\"icon\" href=\"/assets/site/signature.svg\" type=\"image/svg+xml\">\n  <link rel=\"alternate\" type=\"application/atom+xml\" title=\"diasbruno\" href=\"/atom.xml\">\n  <link rel=\"alternate\" type=\"application/json\" href=\"/posts/tests-comes-first-coverage-comes/content.json\">\n  <link rel=\"stylesheet\" href=\"/assets/site/tokens.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/site.css\">\n  <link rel=\"stylesheet\" href=\"/assets/site/footer.css\">\n\n</head>\n<body class=\"light\">\n<div id=\"site-page\">\n<a class=\"skip-link\" href=\"#content\">Skip to content</a>\n<header class=\"site-header\">\n  <a class=\"brand\" href=\"/\" data-site-navigation aria-label=\"Bruno Dias, home\">\n    <img src=\"/assets/site/signature.svg\" width=\"24\" height=\"34\" alt=\"\">\n  </a>\n  <nav aria-label=\"Main navigation\">\n    <ul>\n<li><a class=\"nav-vrn\" href=\"/vrn/\" data-site-navigation><span class=\"nav-label\">vrn</span> <span class=\"nav-badge\">research</span></a></li>\n<li><a class=\"nav-posts\" href=\"/posts/\" data-site-navigation aria-current=\"location\">Posts</a></li>\n<li><a class=\"nav-projects\" href=\"/projects/\" data-site-navigation>Projects</a></li>\n<li><a class=\"nav-about\" href=\"/about/\" data-site-navigation>About</a></li>\n</ul>\n  </nav>\n</header>\n\n<main class=\"section\" id=\"content\" tabindex=\"-1\">\n  <article class=\"post-detail\">\n    <header class=\"section-header\">\n      <p class=\"post-category\">Post</p>\n      <h1>Tests comes first; coverage comes way later</h1>\n<p class=\"post-subtitle\">This should be obvious by now. 100% coverage doesn&#x27;t mean anything, but 0% means a lot.</p>\n      <p><time datetime=\"2025-10-29T22:30:48+00:00\">2025-10-29</time></p>\n    </header>\n    <div class=\"post-columns\">\n      <section class=\"post-body\" aria-label=\"Article\">\n\n<figure><img src=\"/assets/site/substack/tests-comes-first-coverage-comes/figure-1.jpg\" alt=\"\" loading=\"lazy\" width=\"800\" height=\"495\">\n</figure>\n<p>It’s good to have metrics. Metrics for everything. But like in every topic, it’s good to think about stuff.</p>\n<p>100% metric would suggest that “every expression was been executed if it’s required in all test cases - directly or indirectly”. And no surprise, the only output we can get is “how many times an expression was executed”. </p>\n<p>We could try to write an “addition” function and write as many cases we want, still we wouldn’t get any closer to fully test this function.</p>\n<p>We can “hit” any expression at anytime, but we may not trigger all the behaviors (or inputs/outputs) that such an expression can deal with.</p>\n<p>As some kinda tradition at this point, companies and engineers adds to the contribution policy that “any code contributed must keep the project in, at least, at some coverage threshold percentile negotiated with the rest of the team”.</p>\n<p>This creates a lot of in-satisfaction and people doing terrible contributions because tests are annoying to write (if you don’t take care of your testing tools and infrastructure) and some senior also just accepting the contribution because “LEGIT” and move on.</p>\n<p>There is probably no solution yet for this problem (at least for now until AI improves the way it understands how case analysis works, but I believe we’ll get there). So, code reviews are still the best way to “guarantee” code quality.</p>\n<p>In every work, we expect to give some inputs, it performs, possibly, some side-effects,  and gives us the output. This pair of <code>(Input, Output)</code> is actually what we expect as result from any expression or work we do.</p>\n<p>Some cases, testing can be really easy, specially when they are stateless, because you have full control of the input and outputs.</p>\n<p>The other part is a nightmare sometimes. Tests that depends on the state of the world at some moment are quite challenging to get it right when you are beginning to learning about testing.</p>\n<p>You need to know what are the correct states of other dependencies - of the application domain, to avoid cases where some states would be impossible. Then, we need to check what are the possible side-effects and other co-products that happen by doing such a work. </p>\n<p>So, if there is any sorta advice in order to write good tests that keeps the quality of the project good would be to write the most test cases as you can before even start implementing. you can write cases like “string cannot be empty”, “limit of the string should be 3”, “unauthorized users cannot perform this task”, “user with account deactivated cannot perform this task“, “user cannot perform this task after 3pm”…</p>\n<p>Maybe this can give more insights and help you write good tests.</p>\n\n      </section>\n      <aside class=\"post-links\" aria-labelledby=\"post-links-heading\">\n        <h2 id=\"post-links-heading\">Links</h2>\n        <ul>\n<li><a href=\"/posts/\" data-site-navigation>All posts</a></li>\n<li><a href=\"https://diasbruno.substack.com/p/tests-comes-first-coverage-comes\">Original on Substack</a></li>\n        </ul>\n      </aside>\n    </div>\n  </article>\n</main>\n\n<footer class=\"site-footer\">\n  <div class=\"site-footer-inner\">\n    <a class=\"site-footer-home\" href=\"/\" data-site-navigation>Bruno Dias</a>\n    <ul aria-label=\"Footer links\">\n      <li><a href=\"https://github.com/diasbruno\">GitHub</a></li>\n      <li><a href=\"/atom.xml\">Atom feed</a></li>\n    </ul>\n  </div>\n</footer>\n\n</div>\n<script type=\"module\" src=\"/assets/site/navigation.js\"></script>\n</body>\n</html>\n"}
