GoLang Testing

Table of Contents

Running tests

https://stackoverflow.com/questions/16353016/how-to-go-test-all-tests-in-my-project

go test will run the tests only in the directory in which it it run.

e.g. To run tests on morestrings package, we have to run go test in that directory.

How to `go test` all tests in my project?

This should run all tests in current directory and all of its subdirectories. So, we can run it from the root directory of the project.

go test ./...

This should run all tests for given specific directories:

go test ./tests/... ./unit-tests/... ./my-packages/...

This should run all tests with import path prefixed with foo/:

go test foo/...

This should run all tests import path prefixed with foo:

go test foo...

This should run all tests in your $GOPATH:

go test ...

Mocking functions

https://stackoverflow.com/questions/19167970/mock-functions-in-go


Links to this note