Go Testing

Go testing patterns. Routes to specific patterns. Use when this capability is needed.

tomevault-io Updated

File contents

Testing

Route by Pattern

  • Table-driven tests → see table/
  • Subtests with t.Run → see subtests/
  • Test helpers → see helpers/
  • Benchmarks → see benchmarks/

Quick Check

  • Tests named Test_Function_Scenario
  • Table tests for >2 cases
  • Helpers call t.Helper()
  • Parallel tests capture loop vars

Common Patterns

Basic test structure:

func Test_Function_Scenario(t *testing.T) {
    // Arrange
    input := "test"

    // Act
    result := Function(input)

    // Assert
    if result != expected {
        t.Errorf("got %v, want %v", result, expected)
    }
}

Converted and distributed by TomeVault — claim your Tome and manage your conversions.

tomevault-io/skills-registry/tree/main/jamesprial--claudefiles--testing commit 15cc3a2fc8

Frequently asked questions

npx skillmds@latest add tomevault-io/go-testing-4