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.

Learn Go by writing tests – Hello, world

221 pointsby quiiabout 7 years ago

9 comments

mannykannotabout 7 years ago
I think this comment, at the end of the readme, makes too strong a claim: &quot;Write a failing test and see it fail so we know we have written a relevant test for our requirements...&quot; While a test that passes at this point is clearly not a valid test, relevance cannot be assumed from its failure. Tests are not immune from simple coding errors like using the wrong comparison operator, and beyond that, it is possible that the programmer has misunderstood precisely what it means for the intended purpose of the code to be satisfied. I find that a few percent of my tests and assertions are actually incorrect as first written, for both of the above reasons.<p>If you are thinking that I am misunderstanding the purpose of unit tests in TDD, that it is only to check that you have written the code that you intended to write, then that would raise the question of how you address the issue of fitness for purpose - these are two distinct issues, even though the goal is for the former to match the latter.<p>Also, while a test may provide an easy to understand description of the failure, there is no guarantee that all possible failures are so described.<p>Teaching testing as a fundamental part of programming is important, and I like this approach, but I think this particular claim goes a bit too far.
评论 #16563996 未加载
评论 #16568745 未加载
evolve2kabout 7 years ago
The README is much more useful to following the project, it&#x27;s well written and worth a read.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;quii&#x2F;learn-go-with-tests&#x2F;blob&#x2F;master&#x2F;hello-world&#x2F;readme.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;quii&#x2F;learn-go-with-tests&#x2F;blob&#x2F;master&#x2F;hell...</a>
评论 #16562661 未加载
cornholioabout 7 years ago
A common problem I&#x27;m having with coding tutorials is the tendency to copy paste example code and gain only a superficial understanding. My version &quot;works&quot; but a month later I won&#x27;t be able to recreate it from scratch.<p>Your test-driven approach lends itself to hands-on exercises where you introduce the pre-written test cases, explain the new concepts on generic examples, and the person completing the tutorial needs to write the code that gets the test case to pass (or maybe expand a partial solution from you).<p>Once you struggled with the compiler errors, the trial and failure, the syntax, etc. and passed the tests you will gain operational knowledge that will last a lifetime.<p>Also, a chapter zero could be made available for the absolute beginners, detailing how to assemble a free Go environment, for example VS Code + go plugin + golang package + Git SCM + delve debugger. That should get most people running in 10 minutes with a very rich and productive environment.
评论 #16563723 未加载
评论 #16563819 未加载
leetroutabout 7 years ago
Readers may also be interested in the Go koans <a href="https:&#x2F;&#x2F;github.com&#x2F;cdarwin&#x2F;go-koans" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cdarwin&#x2F;go-koans</a><p>Similar approach focusing on writing snippets of code to make tests pass instead of writing the tests themselves.
mattnewtonabout 7 years ago
Skimming this quickly I was surprised that constants Spanish and French were accessible in the test files. Is this a test only scope thing or just how go works?<p>Edit: it’s how to works, specifically with packages. Found this: <a href="https:&#x2F;&#x2F;medium.com&#x2F;golangspec&#x2F;scopes-in-go-a6042bb4298c" rel="nofollow">https:&#x2F;&#x2F;medium.com&#x2F;golangspec&#x2F;scopes-in-go-a6042bb4298c</a>
评论 #16563611 未加载
ruffreyabout 7 years ago
Really well done so far.<p>Hopefully some of Go&#x27;s distinguishing features will make it into the tutorial. Namely channels, custom types, goroutines, and interfaces.
评论 #16563242 未加载
gandalfgeekabout 7 years ago
A great next step in this scenario would be to refactor the test to be table driven. Makes it much easier to to test cases and add more of them.
bogomipzabout 7 years ago
What is the significance of the different vX folders? These are just versions? Maybe I am reading this incorrectly?
评论 #16563378 未加载
davestephensabout 7 years ago
This is awesome, been meaning to have a poke around go for a while - perfect Sunday afternoon noodle. Thank you!