<p>I'm keen to understand if and how people are doing unit, module, and system tests for their Go applications. I've noticed the testing camp is split three ways: some people hate tests, some people don't get them or struggle with them, and some people love them. What are your thoughts? </p>
<p>If you're somewhere in the middle, is it because you're unsure as to how to actually write the tests, what tools to use, how to make it easier, and so? What's stopping you from implementing them?</p>
<p>All thoughts welcome.</p>
<hr/>**评论:**<br/><br/>shovelpost: <pre><p>I consider testing to be a standard engineering practice. Go's tooling and culture make it abundantly clear that tests are part of the code. The <code>testing</code> package and <code>go test</code> make it trivial to write tests. In terms of test quantity for me it goes:</p>
<p>unit tests > integration tests > e2e tests</p>
<p>The testing tools we got are already pretty good and can help you go pretty far without even reaching for an external library which is the default in most other languages. I also think that Go is the only language that makes it easy to have runnable examples as part of the code which serve both as tests and documentation. </p>
<p>Some useful resources:</p>
<ul>
<li><a href="https://golang.org/doc/code.html#Testing" rel="nofollow">https://golang.org/doc/code.html#Testing</a></li>
<li><a href="https://golang.org/pkg/testing/" rel="nofollow">https://golang.org/pkg/testing/</a></li>
<li><a href="https://blog.golang.org/cover" rel="nofollow">The cover story</a></li>
<li><a href="https://talks.golang.org/2014/testing.slide#1" rel="nofollow">Andrew Gerrand - Testing Techniques</a></li>
<li><a href="https://github.com/golang/go/wiki/TableDrivenTests" rel="nofollow">Table Driven Tests</a></li>
<li><a href="https://www.youtube.com/watch?v=8hQG7QlcLBk" rel="nofollow">Mitchell Hashimoto - Advanced Testing with Go</a></li>
</ul></pre>mikecrilly: <pre><p>Good talk. lol</p></pre>shovelpost: <pre><p>I visit the subreddit almost every day and I never saw this post until today. Given this is a new account, it's likely that your post wasn't approved yet by the moderators or something like that. After you make a post, you could try visiting the subreddit logged out to make sure your post it's visible.</p></pre>BACONWART: <pre><p>We write a lot of tests at my work place so it kind of comes to me quite naturally. That being said, I have yet to try out writing tests in Go since I am very new with the language. </p></pre>
Ask Golang: do you do unit, module, AND systems tests and if not, why not? What's stopping you?
blov · · 431 次点击这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传