Run go vet and test commands
Run go vet and test commands
go test ./... runs tests for packages in the current module tree. Use -v for detailed output, -run for name filtering, -count=1 to disable cached test results, and -short to request short mode. go vet ./... analyzes code for suspicious constructs; it is not a proof of correctness. go test already runs a selected subset of vet checks by default.
Create the files shown below in a fresh directory, then run go test -count=1 -v ./... there. The separator lines are file labels, not source code. Go 1.23 is used for these local examples.
--- go.mod ---module example.test/lesson
go 1.23
--- calc.go ---package calc
func Add(a, b int) int { return a + b }
--- calc_test.go ---package calc
import "testing"
func TestAdd(t *testing.T) { if Add(2, 2) != 4 { t.Fatal("sum") }}func TestZero(t *testing.T) { if Add(0, 0) != 0 { t.Fatal("zero") }}Run go vet ./..., then go test -count=1 -run "^TestZero$" -v ./.... Only TestZero is selected. Vet normally emits no output on success. A successful vet run says nothing about whether a particular test was selected.
Expected result (timings and formatting may vary; essential text shown):
--- PASS: TestAddRespect short mode explicitly
--- go.mod ---module example.test/lesson
go 1.23
--- calc.go ---package calc
func Value() int { return 7 }
--- calc_test.go ---package calc
import "testing"
func TestQuick(t *testing.T) { if Value() != 7 { t.Fatal("wrong value") }}func TestExtended(t *testing.T) { if testing.Short() { t.Skip("extended check") } if Value() < 1 { t.Fatal("not positive") }}Run go test -short -count=1 -v ./... and observe TestExtended marked SKIP. Short mode does not automatically classify slow tests; the test checks testing.Short and decides to skip. Review skipped tests and run the complete suite when required.
Expected result (timings and formatting may vary; essential text shown):
--- PASS: TestExtendedTry it locally
Implement IsPositive with tests TestPositive and TestZero. Run the full suite and select TestZero with -run. Run go vet ./.... Use a fresh module with the same go.mod shown above; run go test -count=1 -v ./...
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Testing fundamentals 08: Run go vet and test commands
Check the lesson objective before moving on.
Which command disables successful test result caching?
Does go test -short automatically skip slow tests?