Usually, when I start out to learn something for the first time, I hit up the usual suspects: Pluralsight, Udemy, Linkedin Learning, etc. I really love learning programming topics via video training. For me, I find the instructors usually drop little tidbits of knowledge throughout the course, which is often not included in blog posts. However, when really trying to deep dive into unit testing in Go, I found these resources lacking.
通常,当我第一次开始学习某些东西时,我会遇到一些常见的怀疑对象:Pluralsight,Udemy,Linkedin Learning等。我真的很喜欢通过视频培训来学习编程主题。 对我来说,我发现在整个课程中讲师通常会少讲一些知识,而这些知识通常不包括在博客文章中。 但是,当真正尝试深入Go的单元测试时,我发现缺少这些资源。
Unit testing in Go is a pretty straight-forward task, which is awesome. And this is also why you can find a lot of resources on the basics of testing in Go. When searching for something more targeted, like mocking with interfaces, it can be harder to find quality content. I have put together this list of links to Pluralsight, YouTube, documentation, and blog posts that really helped me dive deeper into testing in Go.
Go中的单元测试是一项非常简单的任务,非常棒。 这也是为什么您可以在Go的测试基础上找到大量资源的原因。 当搜索更具针对性的内容(例如使用接口进行嘲笑)时,很难找到高质量的内容。 我整理了这个指向Pluralsight,YouTube,文档和博客文章的链接列表,这些链接确实帮助我深入了Go的测试。
This is not a definitive list, and I will do my best to update it over time as I run across new resources. However, if you’re new to testing in Go, or haven’t been going deeper than the standard testing package, this post may be beneficial to you.
这不是一个确定的列表,当我使用新资源时,我会尽力更新它。 但是,如果您刚开始使用Go进行测试,或者还没有深入到标准测试包中,那么这篇文章对您可能会有所帮助。
基础 (The Basics)
You have to start somewhere, and learning the basics of unit testing in Go is actually very well covered. Here are some resources to get started.
您必须从某个地方开始,并且实际上已经很好地学习了Go中的单元测试基础。 这里有一些入门资源。
Go — Testing Package Documentation: I always like to start with the official documentation, even though it's not the best resource when you’re first getting started. However, read over this, as once you get in deep you’ll be coming back to this site over and over!
继续-测试软件包文档 :即使您初次使用它不是最佳资源,我也总是喜欢从官方文档开始。 但是,请仔细阅读,一旦深入了解,您将一遍又一遍地回到本网站!
Pluralsight — Creating Well-tested Applications in Go: This is a great course of the basics of unit testing in Go. It's a wonderful introduction to unit testing, benchmark testing, and profiling.
Pluralsight-在Go中创建经过良好测试的应用程序 :这是Go中单元测试基础知识的绝妙课程。 这是对单元测试,基准测试和性能分析的精彩介绍。
YouTube — Testing and Benchmarking in Go Workshop: There is some overlap with the Pluralsight course here, but if you don’t have access to Pluralsight this is an excellent course. Even if you have access, I still recommend watching both.
YouTube – Go Workshop中的测试和基准测试 :此处的Pluralsight课程有一些重叠之处,但是,如果您无权使用Pluralsight,则这是一门极好的课程。 即使您可以访问,我仍然建议您同时观看两者。
HTTP测试 (HTTP Testing)
I find that the majority of code I write in Go these days are REST services. Luckily, testing your endpoints is very easy and these links can walk you through how to do it.
我发现这些天我在Go中编写的大多数代码都是REST服务。 幸运的是,测试端点非常简单,这些链接可以引导您完成操作。
Go — HTTPTest Package Documentation: Again, start with the official documentation to get familiar with what’s in it. You’ll be back on this page very often!
继续-HTTPTest软件包文档 :再次,从官方文档开始,以熟悉其中的内容。 您会经常回到此页面!
Blog — Testing Your (HTTP) Handlers in Go: A great, to the point, post about how to test endpoints and handlers in your Go REST service. Examples here are simple and easy to understand and provide information around how to craft the test and pass data to your endpoint. This post will give you an excellent starting point for these tests.
博客—在Go中测试您的(HTTP)处理程序 :重点在于,发布有关如何在Go REST服务中测试终结点和处理程序的文章。 这里的示例简单易懂,并提供有关如何进行测试并将数据传递到端点的信息。 这篇文章将为您提供这些测试的绝佳起点。
YouTube — justforfunc #16: unit testing HTTP servers: Similar to the blog post above, this video gives an excellent introduction to testing your REST service using the
httptest
package.YouTube — justforfunc#16:HTTP服务器的单元测试 :与以上博客类似,该视频很好地介绍了如何使用
httptest
软件包测试REST服务。
基准测试和分析 (Benchmarking & Profiling)
I absolutely love the benchmarking and profiling tools in Go. I can say with confidence this is an area that most developers ignore. This is through no fault of their own, as most teams don’t have their product owners asking about performance. However, as an engineer, you should really be concerned about it and always looking for potential areas of concern.
我绝对喜欢Go中的基准测试和性能分析工具。 我可以自信地说这是大多数开发人员都忽略的领域。 这绝不是他们自己的错,因为大多数团队没有产品负责人来询问性能。 但是,作为工程师,您应该真正关心它,并始终在寻找潜在的关注领域。
YouTube — justforfunc #28: Basic Benchmarks: A good introduction to benchmark testing in Go. This video will complement the Pluralsight and YouTube videos from above in the basics section, but its some live coding with commentary, which I love!
YouTube — justforfunc#28:基本基准 :Go中基准测试的良好介绍。 该视频将补充“基础知识”部分中上方的Pluralsight和YouTube视频,但其中一些带有注释的实时编码非常喜欢!
Blog — Profile your golang benchmark with pprof: Very simple and to the point post about using Go’s pprof profiling tool.
博客—使用pprof描述您的golang基准测试 :非常简单,并且是有关使用Go的pprof分析工具的要点。
YouTube — GopherCon 2019: Dave Cheney — Two Go Programs, Three Different Profiling Techniques: Love this video! Live coding, what could go wrong?! Deep dive into how to profile your application, then a look into how to fix issues you may find.
YouTube — GopherCon 2019:Dave Cheney —两个Go程序,三种不同的分析技术 :喜欢这个视频! 实时编码,怎么可能出问题了?! 深入研究如何分析应用程序,然后研究如何解决可能发现的问题。
模拟与界面 (Mocking & Interfaces)
This can be a daunting task if you’re new to the language, or software engineering in general. However, once you see it practice and do it a couple of times, the mystery is gone and you’ll be a pro at it. These resources provide a concise and easy to follow examples to get you going.
如果您是该语言的新手,或者是一般的软件工程,那么这可能是一项艰巨的任务。 但是,一旦您看到它可以练习并执行了几次,这个谜团就消失了,您将成为专家。 这些资源提供了一个简洁易懂的示例,助您一臂之力。
Go — A Tour of Go (Interfaces): This is the interfaces section, which comes with a great split screen of documentation and the Go Playground. Its only 6 pages but provides all the foundational information needed to understand interfaces and setup you up for the next links.
围棋—围棋之旅(接口) :这是界面部分,它带有大量的文档资料和围棋场。 它只有6页,但是提供了了解界面并为您建立下一个链接所需的所有基本信息。
YouTube — How to mock in your Go tests — Golang Tutorial: I love this video so much, I took an image from it and used it as the image on this post. A great example of building out a test, then refactoring it to use interfaces so you can mock it. Also, a great explanation of when to use interfaces/mocks vs plain unit tests.
YouTube —如何在Go测试中模拟— Golang教程 :我非常喜欢这个视频,我从中拍摄了一张图片,并将其用作本文的图片。 构造测试,然后将其重构为使用接口的一个好例子,您可以对其进行模拟。 此外,还对何时使用接口/模拟与普通单元测试进行了很好的解释。
YouTube — dotGo 2014 — Gabriel Aszalos — Mocking in Go: Using interfaces for fun and profits: This is an excellent lightning talk with some solid examples of an interface followed immediately by how you can mock it and use it. Less than 5 minutes long, but packed full of great learnings.
YouTube – dotGo 2014 – Gabriel Aszalos –模拟中:使用界面带来的乐趣和收益 :这是一个精彩的闪电演讲,提供了一些可靠的界面示例,后面紧接着是您如何模拟和使用它。 不到5分钟的时间,但充满了很多学习成果。
高级 (Advanced)
With any topic in software engineering, you can scrape the surface or go really deep. Fortunately, 99.9% of us can stay near the surface and do just fine. But if you need (or want) to go further, read on!
关于软件工程的任何主题,您都可以刮擦表面或深入了解。 幸运的是,我们中99.9%的人可以留在地表附近,并且做得很好。 但是,如果您需要(或想进一步),请继续阅读!
YouTube — GopherCon 2017: Mitchell Hashimoto — Advanced Testing with Go: Great presentation by Mitchell Hashimoto who works at HashiCorp, and provides a great overview of various aspects of testing in Go. He also details how HashiCorp uses some of the topics he discusses. Nothing too in-depth here, but is a great informational video for further learnings.
YouTube — GopherCon 2017:Mitchell Hashimoto-Go的高级测试:Mitchell Hashimoto的出色演讲,他在HashiCorp工作,并概述了Go中测试的各个方面。 他还详细介绍了HashiCorp如何使用他讨论的某些主题。 这里没有太深入的内容,但是是一个很好的参考视频,可供您进一步学习。
结语 (Wrapping Up)
I hope you find these resources as helpful as I did. As stated at the beginning, this is not meant to be a complete list of links. I plan to add more as I come across them, and will do my best to keep this page updated. If you have a resource that really helped you, please leave it in the comments, and I’ll add it here. I for one know I will be back on this page often!
希望您能像我一样对这些资源有所帮助。 如开头所述,这并不意味着链接的完整列表。 我计划在遇到这些问题时添加更多内容,并会尽力使此页面保持更新。 如果您有真正有用的资源,请将其保留在评论中,我将在此处添加。 我知道我会经常回到该页面!
翻译自: https://levelup.gitconnected.com/go-testing-essential-learning-path-2b7bb61b1030