learn-go-with-tests README

The project's README from github.com/quii/learn-go-with-tests. As one markdown file: README.md.

Learn Go with Tests

Art by Denise

Go Report Card

Formats

Translations

Support me

I am proud to offer this resource for free, but if you wish to give some appreciation:

Why

Table of contents

Go fundamentals

  1. Install Go - Set up environment for productivity.
  2. Hello, world - Declaring variables, constants, if/else statements, switch, write your first go program and write your first test. Sub-test syntax and closures.
  3. Integers - Further Explore function declaration syntax and learn new ways to improve the documentation of your code.
  4. Iteration - Learn about for and benchmarking.
  5. Arrays and slices - Learn about arrays, slices, len, varargs, range and test coverage.
  6. Structs, methods & interfaces - Learn about struct, methods, interface and table driven tests.
  7. Pointers & errors - Learn about pointers and errors.
  8. Maps - Learn about storing values in the map data structure.
  9. Dependency Injection - Learn about dependency injection, how it relates to using interfaces and a primer on io.
  10. Mocking - Take some existing untested code and use DI with mocking to test it.
  11. Concurrency - Learn how to write concurrent code to make your software faster.
  12. Select - Learn how to synchronise asynchronous processes elegantly.
  13. Reflection - Learn about reflection
  14. Sync - Learn some functionality from the sync package including WaitGroup and Mutex
  15. Context - Use the context package to manage and cancel long-running processes
  16. Intro to property based tests - Practice some TDD with the Roman Numerals kata and get a brief intro to property based tests
  17. Maths - Use the math package to draw an SVG clock
  18. Reading files - Read files and process them
  19. Templating - Use Go's html/template package to render html from data, and also learn about approval testing
  20. Generics - Learn how to write functions that take generic arguments and make your own generic data-structure
  21. Revisiting arrays and slices with generics - Generics are very useful when working with collections. Learn how to write your own Reduce function and tidy up some common patterns.

Build an application

Now that you have hopefully digested the Go Fundamentals section you have a solid grounding of a majority of Go's language features and how to do TDD.

This next section will involve building an application.

Each chapter will iterate on the previous one, expanding the application's functionality as our product owner dictates.

New concepts will be introduced to help facilitate writing great code but most of the new material will be learning what can be accomplished from Go's standard library.

By the end of this, you should have a strong grasp as to how to iteratively write an application in Go, backed by tests.

Testing fundamentals

Covering other subjects around testing.

Questions and answers

I often run in to questions on the internets like

How do I test my amazing function that does x, y and z

If you have such a question raise it as an issue on github and I'll try and find time to write a short chapter to tackle the issue. I feel like content like this is valuable as it is tackling people's real questions around testing.

Meta / Discussion

Contributing

Background

I have some experience introducing Go to development teams and have tried different approaches as to how to grow a team from some people curious about Go into highly effective writers of Go systems.

What didn't work

Read the book

An approach we tried was to take the blue book and every week discuss the next chapter along with the exercises.

I love this book but it requires a high level of commitment. The book is very detailed in explaining concepts, which is obviously great but it means that the progress is slow and steady - this is not for everyone.

I found that whilst a small number of people would read chapter X and do the exercises, many people didn't.

Solve some problems

Katas are fun but they are usually limited in their scope for learning a language; you're unlikely to use goroutines to solve a kata.

Another problem is when you have varying levels of enthusiasm. Some people just learn way more of the language than others and when demonstrating what they have done end up confusing people with features the others are not familiar with.

This ends up making the learning feel quite unstructured and ad hoc.

What did work

By far the most effective way was by slowly introducing the fundamentals of the language by reading through go by example, exploring them with examples and discussing them as a group. This was a more interactive approach than "read chapter x for homework".

Over time the team gained a solid foundation of the grammar of the language so we could then start to build systems.

This to me seems analogous to practicing scales when trying to learn guitar.

It doesn't matter how artistic you think you are, you are unlikely to write good music without understanding the fundamentals and practicing the mechanics.

What works for me

When I learn a new programming language I usually start by messing around in a REPL but eventually, I need more structure.

What I like to do is explore concepts and then solidify the ideas with tests. Tests verify the code I write is correct and documents the feature I have learned.

Taking my experience of learning with a group and my own personal way I am going to try and create something that hopefully proves useful to other teams. Learning the fundamentals by writing small tests so that you can then take your existing software design skills and ship some great systems.

Who this is for

What you'll need

Feedback

MIT license

Logo is by egonelbre What a star!

learn-go-with-tests (quii/learn-go-with-tests)

Searching Database…

这是什么?这是一本免费的书,通过先编写测试的方式教你 Go 编程语言,遵循测试驱动开发(TDD)的实践方法。
这是一本书还是一个代码库?这是一本文字教程,可在 Gitbook、EPUB 或 PDF 上获取。全书由若干章节组成,每章都有代码示例和练习供你逐步完成,它不是需要导入的代码库。
我该如何开始阅读并跟着练习?在 Gitbook 上按顺序阅读各章(或下载 EPUB/PDF 版本),在文本编辑器中自己动手编写示例代码,边写边运行测试。
开始之前我需要准备什么?只需要一台已安装 Go 的电脑、一个文本编辑器,以及基本的编程知识(条件判断 if、变量、函数),并且会使用终端。
这本书已经写完了吗?还没有。作者明确表示这本书仍在编写中,会根据读者的提问和贡献不断充实内容。
这本书适合哪些人?它面向初次接触 Go 的人,也面向已经懂一些 Go、但想专门学习 TDD 的人。
作者为什么不直接推荐现有的 Go 书籍,而是自己写一本?作者尝试过集体研读一本内容详细的 Go 书籍,也尝试过和团队一起做 kata 练习,但发现两者要么太慢,要么缺乏条理。他发现编写小型测试来巩固概念效果最好,于是围绕这种方法编写了这份资料。
除了英文,这本书还有其他语言版本吗?有。社区已经提供了多个译本,包括中文、葡萄牙语、日语、法语、韩语、土耳其语、波斯语、荷兰语、越南语和俄语。
我可以询问目前还没有涵盖的测试话题吗?可以。你可以在 GitHub 上提交一个 issue,描述你的测试问题,作者可能会编写新的章节来解答。
除了基础内容,这本书还涵盖哪些主题?内容包括:操作系统 exec 调用、自定义错误类型、支持取消操作且能感知上下文的 io.Reader、HTTP 处理器测试,以及一章专门讨论 TDD 反模式的总结性章节。
Creator
quii
Size
9.5 MB
Stars
23.9K
Age
8y
Commits · 90 Days