1. Write code
1) punch GoLand, new project named gotest
2) In the new two gotest go file directory, as shown below:
Wherein CircleArea.go to calculate the area of a circle go test procedure, as follows:
The gotest Package
Import "Math"
FUNC GetCircleArea (RADIUS float32) float32 {
return Math.PI * * RADIUS RADIUS
}
CircleArea_test.go for the test program, as follows:
The gotest Package
Import "Testing"
// functional test
/ *
FUNC TestGetCircleArea (T * testing.T) {
Area: = GetCircleArea (4.0)
! = 50.265484 {IF Area
( "! test fails") t.Error
} the else {
T .log ( "test passed")
}
} * /
// stress tests
const = N. 3
FUNC TestGetCircleArea (T * testing.T) {
for I: = 0; I <N; I ++ {
Area: = GetCircleArea (4.0)
IF Area! = 50.265484 {
t.Error ( "test failed!")
} the else {
t.Log ( "test passed")
}
}
}
2.Perform tests
1) and stress testing function
execution command in the terminal: Go Test -v