gotest

go get github.com/tracera-dev/tracera-go/gotest

Requires Go ≥ 1.25 (see Autotest adapters). gotest on pkg.go.dev.

Environment variables and run mode: Autotest adapters.

Wire reporting once from TestMain:

package checkout_test

import (
    "os"
    "testing"

    "github.com/tracera-dev/tracera-go/gotest"
)

func TestMain(m *testing.M) {
    os.Exit(gotest.Run(m))
}

Bind testCaseId and autotestName

Use stock testing and imperative bind:

func TestCheckout(t *testing.T) {
    gotest.TestCase(t, 42)
    // gotest.TestCase(t, 42, "e2e/checkout")
}

In parallel tests, call t.Parallel() before gotest.TestCase.

Skip

Use gotest.Skip / gotest.Skipf so the reason is added to the result as comment (stock t.Skip alone does not):

func TestCheckout(t *testing.T) {
    gotest.TestCase(t, 42)
    gotest.Skip(t, "needs a seeded account")
}

Steps

Use tracera.Step("…", func() { … }). Go has no method-step decorator. Steps inside tracera.Setup / tracera.Teardown go to Setup / Teardown; other steps go to Test.

A panic inside tracera.Step adds the error message to the result card. If the test fails with t.Fatal / t.Error, the result is still Failed, but the failure text stays in the go test output only.

import "github.com/tracera-dev/tracera-go"

func TestCheckout(t *testing.T) {
    gotest.TestCase(t, 10)

    tracera.Setup("open shop", func() {})
    tracera.Step("add item", func() {
        tracera.Step("nested leaf", func() {})
    })
    tracera.Teardown("close shop", func() {})
}

Comments, errors, and attachments

Limits and allowed MIME types: Autotest adapters.

tracera.Comment, tracera.Error, and attachments are added to the open step, or to the result when no step is open. tracera.AttachmentFile takes a file path; tracera.AttachmentBytes takes a name, bytes, and MIME type. Attachments upload when the result is reported.

import tracera "github.com/tracera-dev/tracera-go"

tracera.Comment("result-level note")
tracera.Error("result-level error")
tracera.AttachmentFile("testdata/screenshot.png")
tracera.Step("open login", func() {
    tracera.Comment("step note")
    tracera.AttachmentBytes("body.json", []byte(`{"ok":true}`), "application/json")
})

If you start a goroutine and call Tracera APIs there (steps, comments, errors, attachments), save the context on the test goroutine first and run the worker with tracera.RunWithContext — otherwise those calls are not reported:

ctx := tracera.GetContext()
go tracera.RunWithContext(ctx, func() {
    tracera.Step("worker", func() { /* ... */ })
})

Parameterized

Use t.Run rows. Pass a name on TestCase when you want a stable label per row:

func TestMatrix(t *testing.T) {
    for _, row := range []struct{ login string }{{"alice"}, {"bob"}} {
        t.Run(row.login, func(t *testing.T) {
            gotest.TestCase(t, 7, "login as "+row.login)
        })
    }
}