Skip to content

Latest commit

 

History

History
54 lines (34 loc) · 1.57 KB

README.md

File metadata and controls

54 lines (34 loc) · 1.57 KB

Golang testing primer

Introduction

This project was written as part of a training session aiming to provide guidance on how write unit tests in Golang.

Get started

Requisites

This tutorial examples require docker and golang to be installed. It was tested using Go 1.13 for darwin.

CLI help

The included makefile aims to facilitate trying out the examples

  • make test: executes all the test
  • make bench: executes all the benchmark
  • make godoc: runs a dockerized version of godoc that you can open locally http://localhost:6060

Tip

The tests are separated in arrange / act / assert sections to conveniently expose to the reader what's the preconditions or setup for the test, the functionality being tested, and the expected results of the test. This is also a good pattern to follow to ensure your tests are readable and maintainable.

Section

This tutorial is organized in three sections. Feel free to read the examples and comments.

Basics - Introduction to the Golang testing tooling

Assert - Introduction to stretchr/testify/assert

Mocking - Introduction to mocking with stretchr/testify/mock