Intro

I’ve been learning the Go programming language in earnest this week. (See Why Go.)

I believe that test-driven development (TDD) makes me write better code, so I wanted to start with tests.

Testing and assertions

I found an excellent paid resource, The Go Testing Bible video series. The author, Elliot Forbes, posts free videos on his TutorialEdge YouTube channel.

Go has a robust testing package in its standard library. However, the testing syntax looked strange to me because it doesn’t use test assertions like I’m used to from languages like Node (JavaScript), Ruby, Python, and (my favorite) Elm.

Fortunately, the Go Testing Bible (and the free YouTube channel) pointed me in the direction I needed with Getting Started with Testify. Testify is a testing library that includes assertions like the ones I know.

Watch mode

Go testing, like most things in Go, is fast. This is really important to me. Perhaps I’m doing something wrong, but when I unit test in F# or use a JavaScript testing framework like Jest, I get frustrated by the wait times.

On the other hand, I could not find a built-in file watcher that would re-run tests when I modified source or test files. The --watch flag is common in other test runners. I don’t know if my search-engine skills are bad or if most Gophers roll their own solutions to this program, but I found little information about this topic on the web.

I solved the file-watching problem with Go Watch. It’s a tiny package. I installed it with go install github.com/mitranim/gow@latest. To use it, I replaced go test with gow test (“go watch”).

Color output

My last step was creating color output. There might have been a better way to do this, but I found a Stack Overflow post recommending grc (generic colouriser) command-line utility.