Learn Go with test-driven development
Clone or download
Failed to load latest commit information.
arrays lint issues fixed and check is wired up to build #37 Apr 10, 2018
command-line fix grammar on command-line Sep 24, 2018
concurrency fixes #79 Jun 21, 2018
di lint issues fixed and check is wired up to build #37 Apr 10, 2018
for wip - making the code pass go lint Apr 9, 2018
hello-world wip - making the code pass go lint Apr 9, 2018
http-server verboseness in tests is nice Apr 28, 2018
integers wip - making the code pass go lint Apr 9, 2018
io Fix name of tests for recording wins of new players Aug 27, 2018
json further progress on io and a slight fix to json chapter May 28, 2018
maps world help if i actually used refactoring tools Jul 6, 2018
mocking added v5 with sleeper tests May 20, 2018
pointers Marks functions as test helper May 21, 2018
reflection fixes #123 - intermittent failure because of maps not guaranteeing order Aug 25, 2018
select lets not complicate matters with interface{} yet Apr 18, 2018
structs lint issues fixed and check is wired up to build #37 Apr 10, 2018
time fmt Oct 12, 2018
todo more work on websockets and start of todo thing Oct 21, 2018
websockets vendoring deps to fix the build in travis hopefully Nov 5, 2018
.editorconfig improve editorconfig Jun 18, 2018
.gitignore wip - cl - teasing towards using bufio.NewReader Jul 6, 2018
.mdlrc not allow MD010 hard tabs in Markdown files Jun 18, 2018
.travis.yml Bump Go versions Oct 27, 2018
LICENSE.md better put in a license someday Apr 7, 2018
README.md clarification on what a package is Oct 7, 2018
SUMMARY.md time is done Aug 27, 2018
app-intro.md time is done Aug 27, 2018
arrays-and-slices.md Fix typos and other small things Sep 1, 2018
book.json remove trailing space Apr 29, 2018
build.epub.sh another go for pandoc with docker Sep 14, 2018
build.sh more work on websockets and start of todo thing Oct 21, 2018
command-line.md fix grammar on command-line Sep 24, 2018
concurrency.md fixes #122 - adds note about running benchmarks in powershell, thanks @… Aug 25, 2018
contributing.md Fix link to chapter template in contributing.md Jun 25, 2018
dependency-injection.md trivial grammar and style tweak on di Jun 18, 2018
gb-readme.md add Chinese translation link for online reading Jul 4, 2018
hello-world.md clarification on what a package is Oct 7, 2018
http-server.md Name the function which holds our subtest. Oct 3, 2018
install-go.md fixed typo: 'not' to 'note'; updated go tools cmd Jul 17, 2018
integers.md Add a missing space and remove a word Aug 21, 2018
io.md Rename `FileSystemStore` to `FileSystemPlayerStore` Nov 4, 2018
iteration.md fixes #122 - adds note about running benchmarks in powershell, thanks @… Aug 25, 2018
json.md trivial grammar and style tweak on json.md Jul 2, 2018
maps.md add some sentences to make the context coherent Aug 19, 2018
mocking.md Typo in Sleep() function Jul 11, 2018
pointers-and-errors.md Convert int to Bitcoin type. Aug 11, 2018
reflection.md trivial grammar and style tweak on reflection.md Sep 22, 2018
select.md remove WIP status, fix a space Jun 23, 2018
structs-methods-and-interfaces.md Add missing word Sep 1, 2018
template.md fix blank line Apr 29, 2018
time.md time is done Aug 27, 2018
title.txt script to build epub Sep 14, 2018
websockets.md more work on the WebSockets Oct 26, 2018
why.md corrections Oct 26, 2018


Learn Go with tests

Or learn test-driven development with Go

Build Status Go Report Card

You can read this on Gitbook

Translations: 中文


  • Explore the Go language by writing tests
  • Get a grounding with TDD. Go is a good language for learning TDD because it is a simple language to learn and testing is built-in
  • Be confident that you'll be able to start writing robust, well-tested systems in Go

Table of contents

If there's no link, it's not done yet! why not contribute?

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

Property-based tests (todo)

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.

  • HTTP server - We will create an application which listens to HTTP requests and responds to them.
  • JSON, routing and embedding - We will make our endpoints return JSON and explore how to do routing.
  • IO and sorting - We will persist and read our data from disk and we'll cover sorting data.
  • Command line & project structure - Support multiple applications from one code base and read input from command line
  • Time - using the time package to schedule activities


  • This project is work in progress If you would like to contribute, please do get in touch.
  • Read contributing.md for guidelines
  • Any ideas? Create an issue


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

  • People who are interested in picking up Go.
  • People who already know some Go, but want to explore testing with TDD.

What you'll need

  • A computer!
  • Installed Go
  • A text editor
  • Some experience with programming. Understanding of concepts like if, variables, functions etc.
  • Comfortable with using the terminal


MIT license

Logo is by egonelbre What a star!