Golang test
Overview
golang test 내용정리.
Basic
Package testing provides support for automated testing of Go packages. It is intended to be used in concert with the "go test" command, which automates execution of any function of the form
func TestXxx(*testing.T)
where Xxx does not start with a lowercase letter. The function name serves to identify the test routine.
With these functions, use the Error, Fail or related methods to signal failure.
To write a new test suite, create a file whose name ends _test.go that contains the TestXxx functions are described here. Put the file in the same package as the one being tested. The file will be excluded from regular package builds but will be included when the "go test" command is run. For more detail, run "go help test" and "go help testing".
A simple test function looks like this:
fund TestAbs(t *testing.T) { got := Abs(-1) if got != 1 { t.Errorf("Abs(-1) = %d; want 1", got) } }
TestMain
See also
- https://golang.org/pkg/testing/ - Package testing