go_test
go_test runs go test from project root with the selected managed SDK. By default it tests every package under the project. It registers the command as a root task and returns its dependency.
Arguments
| Argument | Required | Description |
|---|---|---|
packages | No | Non-empty package patterns. Defaults to ["./..."]. |
deps | No | Dependencies activated before testing, in list order. Defaults to []. |
run | No | Regular expression passed as -run when non-empty. |
count | No | Non-negative test count passed as -count; use 1 to disable cached results. |
timeout | No | Duration passed as -timeout when non-empty. |
race | No | Enable race detection with -race. Defaults to False. |
cover | No | Enable coverage analysis with -cover. Defaults to False. |
short | No | Enable short mode with -short. Defaults to False. |
verbose | No | Enable verbose output with -v. Defaults to False. |
fail_fast | No | Stop after the first package test failure with -failfast. Defaults to False. |
flags | No | Additional string flags appended after package paths. Defaults to []. |
Because flags follows package paths, it can carry test-binary flags and -args.
Examples
Test all packages
load("@[email protected]", "go_test")
go_test()
Test selected packages without cached results
load("@[email protected]", "go_test")
go_test(
packages=["./runner/...", "./internal/..."],
count=1,
timeout="2m",
)
Run race and coverage checks
load("@[email protected]", "go_test")
load("@os@1", "env_set")
go_test(
race=True,
cover=True,
fail_fast=True,
deps=[env_set("CGO_ENABLED", "1")],
)