August 2019
Beginner to intermediate
798 pages
17h 2m
English
If the go test tool takes too much time to finish or for some reason it never ends, there is the -timeout parameter. In order to illustrate that, we are going to create a new Go program along with its tests.
The Go code of the main package, which is saved as too_long.go, is the following:
package main
import (
"time"
)
func sleep_with_me() {
time.Sleep(5 * time.Second)
}
func get_one() int {
return 1
}
func get_two() int {
return 2
}
func main() {
}
The testing functions, which are saved in too_long_test.go, will be as follows:
package main import ( "testing" ) func Test_test_one(t *testing.T) { sleep_with_me() value := get_one() if value != 1 { t.Errorf("Function returned %v", value) } sleep_with_me() ...Read now
Unlock full access