Running unit tests
Use the Go build system tools to run unit tests.
How to do it...
- To run all unit tests in the current package, input the following:
go test PASS ok github.com/PacktPublishing/Go-Recipes-for-Developers/src/chp17/sorting/sort 0.001s
- To run all unit tests in a package, input the following:
go test <packageName>
Or, input the following:
go test ./<folder>
Here is an example:
go test github.com/PacktPublishing/Go-Recipes-for-Developers/src/chp17/sorting/sort
Or, you can input the following:
go test ./sorting
- To run all unit tests in all packages of a module recursively, input the following:
go test ./...
Do this from the root directory of the module.
- To run a single test in the current package, input the following:
go test -run TestSortTimesAscending
This form treats the test name after the
-run
flag as a regular expression and runs all tests that contain that string. For instance,go test -run Sort
will run all tests...