August 2016
Beginner to intermediate
665 pages
14h 11m
English
As with many of the basic and intermediate development and deployment requirements you may have, Go comes with a built-in application for handling unit tests.
The basic premise behind testing is that you create your package and then create a testing package to run against the initial application. The following is a very basic example:
mathematics.go
package mathematics
func Square(x int) int {
return x * 3
}
mathematics_test.go
package mathematics
import
(
"testing"
)
func Test_Square_1(t *testing.T) {
if Square(2) != 4 {
t.Error("Square function failed one test")
}
}A simple Go test in that subdirectory will give you the response you're looking for. While this was admittedly simple—and purposefully flawed—you can probably ...