Testing with Go
Go has a built in test framework. It’s lightweight. Just go test.
Simply:
- For the file of types, functions, etc. you want to test, create a file ending in
_test.go - Import the standard library
testingpackage. - In that file, write functions that start with
TestXXX - Each function gets called with an argument called
t. Thistobject is an instance oftesting.Tand is used to pass/fail your tests. - If
t.Errorort.Failis called, the test is considered failed. - Run
go test - you can also run benchmarking tests with the go tool, using the
--benchflag - Due to the minimalistic nature of the go testing framework, manual setup/teardown is necessary and expected
Last modified:
Last modified: