TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Visualize code coverage as you write your code

2 pointsby justinlillyabout 10 years ago

1 comment

dalkeabout 10 years ago
&gt; If you follow TDD, you ensure the line of code is covered by writing the test first, ensuring it fails, then writing the line that makes it pass.<p>This isn&#x27;t quite true. There are two ways to lose line coverage. The first is if new code duplicates a case that was previous caught elsewhere. For example, suppose current code handles n&gt;=0, with a special where n=0 returns 0, and the new code handles n&lt;=0 by returning 0.<p>It&#x27;s not always clear when new code shadows the old code path, leaving it with under 100% coverage.<p>The other way is through refactoring. My usual example is to replace string search implementation using the naive O(n*m) algorithm with the KMP algorithm, keeping the API unchanged. The KMP machinery is more complicated, and it&#x27;s unlikely that the tests used to drive the naive implementation will be enough to validate the refactor.<p>Following the &quot;fear-driven development&quot; methodology means adding more test until you&#x27;re confident the refactor was valid. But this is &quot;test last&quot;, and not part of TDD.<p>I&#x27;m much more an FDD practitioner than I am a TDD one. :) And the idea of live code coverage sounds great to me.