For example, there is a simple function:
func add(x, y int) int { return x + y }
What are the built-in tools that allow it to test?
For example, there is a simple function:
func add(x, y int) int { return x + y }
What are the built-in tools that allow it to test?
There is a gotest command. For the sample package, running the gotest command will return a PASS test.
Sample.go file:
package sample func Add(x, y int) int { return x + y }
Sample_test.go file:
package sample import "testing" func TestAdd(t *testing.T) { var x, y, z int = 1, 2, 3 if z != Add(x, y) { t.Errorf("%d != %d", z, x + y) } }
Makefile:
include $(GOROOT)/src/Make.inc TARG=sample GOFILES=sample.go include $(GOROOT)/src/Make.pkg
Source: https://ru.stackoverflow.com/questions/407/
All Articles