go_test
go_test runs go test from the project root with the selected managed SDK. By default it tests every package under the project. Tests run during xx run; pass the returned dependency to deps when another task must wait for them.
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 []. |
Use flags for test-binary flags. Include -args before arguments that must be passed directly to the test binary.
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")],
)