TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Learn Go by writing tests – Hello, world

221 点作者 quii大约 7 年前

9 条评论

mannykannot大约 7 年前
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 未加载
evolve2k大约 7 年前
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 未加载
cornholio大约 7 年前
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 未加载
leetrout大约 7 年前
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.
mattnewton大约 7 年前
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 未加载
ruffrey大约 7 年前
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 未加载
gandalfgeek大约 7 年前
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.
bogomipz大约 7 年前
What is the significance of the different vX folders? These are just versions? Maybe I am reading this incorrectly?
评论 #16563378 未加载
davestephens大约 7 年前
This is awesome, been meaning to have a poke around go for a while - perfect Sunday afternoon noodle. Thank you!