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.

Show HN: A tool that renders your tests as readable documentation

1 pointsby gus_leonelover 2 years ago

1 comment

gus_leonelover 2 years ago
I came up with this idea because I was trying to encourage people to think about how they name their tests. One useful technique is to make the test name a complete (but brief) sentence describing the required behaviour.<p>This is helpful when the test fails, because you see the name printed out as part of the failure message. But it&#x27;s also a good thinking tool as you&#x27;re <i>writing</i> the test, because you have to start by deciding exactly what the behaviour under test should be.<p>As some guy named Sam Altman said, &quot;If it takes more than a sentence to explain what you&#x27;re doing, that&#x27;s almost always a sign that it&#x27;s too complicated.&quot; This is a good guide for programmers too, because the amount of behaviour that can be concisely described in a sentence is also about the right amount for a software component or function.<p>Hence a program that parses your (Go) test names, eliminating camel case and underscores and so forth, and prints them out as readable English sentences. For example, if the test name is &#x27;TestFooReturnsErrorForInvalidInput&#x27;, the program will print:<p><pre><code> Foo returns error for invalid input </code></pre> (preceded by a tick or a cross to show the current test status)<p>To try it out, run:<p><pre><code> go install github.com&#x2F;bitfield&#x2F;gotestdox&#x2F;cmd&#x2F;gotestdox@latest </code></pre> Then run &#x27;gotestdox&#x27; in some Go project or package (the default target is the current package, but it can also take any arguments that &#x27;go test&#x27; takes, such as a package list like &#x27;.&#x2F;...&#x27;).<p>The original implementation of this simple but useful idea was &#x27;agiledox&#x27;, written by Chris Stevenson for JUnit. It has been ported to various other languages and test frameworks, but not (as far as I know) to Go, until now.<p>I wrote an article explaining in more depth why I think test names should be written as sentences, and how &#x27;gotestdox&#x27; can help with that: <a href="https:&#x2F;&#x2F;bitfieldconsulting.com&#x2F;golang&#x2F;test-names" rel="nofollow">https:&#x2F;&#x2F;bitfieldconsulting.com&#x2F;golang&#x2F;test-names</a>