xx
.md

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

ArgumentRequiredDescription
packagesNoNon-empty package patterns. Defaults to ["./..."].
depsNoDependencies activated before testing, in list order. Defaults to [].
runNoRegular expression passed as -run when non-empty.
countNoNon-negative test count passed as -count; use 1 to disable cached results.
timeoutNoDuration passed as -timeout when non-empty.
raceNoEnable race detection with -race. Defaults to False.
coverNoEnable coverage analysis with -cover. Defaults to False.
shortNoEnable short mode with -short. Defaults to False.
verboseNoEnable verbose output with -v. Defaults to False.
fail_fastNoStop after the first package test failure with -failfast. Defaults to False.
flagsNoAdditional 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")],
)