29
loading...
This website collects cookies to deliver better user experience
package shorttest
import (
"fmt"
"time"
)
func DoUnimportantStuff() uint8 {
fmt.Println("Doing unimportant stuff")
time.Sleep(10 * time.Second)
return 1
}
func DoImportantStuff() uint8 {
fmt.Println("Doing important stuff")
return 1
}
package shorttest
import "testing"
func TestImportant(t *testing.T) {
got := DoImportantStuff()
if got != 1 {
t.Errorf("Important stuff not correct, needed %d", got)
}
}
func TestUnimportant(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
} else {
got := DoUnimportantStuff()
if got != 1 {
t.Errorf("Unimportant stuff not correct, needed %d", got)
}
}
}
$ go test
Doing important stuff
Doing unimportant stuff
PASS
ok shorttest 10.364s
--short
flag.❯ go test --short
Doing important stuff
PASS
ok shorttest 0.116s
--short
via testing.Short()
in the non-critical and long running tests.