golang testing

AI Community

Skill notes

When to Use

Writing new unit, integration, or package-level tests for Go code Refactoring tests toward idiomatic Go structure and stronger signal Reviewing Go test suites for maintainability, determinism, and coverage gaps Designing fakes, mocks, or test seams around external dependencies

Default Testing Stance

Unless there is a clear reason not to, prefer these defaults: Use black-box tests with an external test package: package mypkg_test Test public behaviour and interfaces, not internal implementation details Use one top-level test function per public function/method/behaviour, with subtests for scenarios Call t.Parallel() by default in top-level tests and subtests unless shared state, process-wide mutation, timing, or external resources make it unsafe

Core Principles

Behaviour over implementation - Assert externally visible outcomes Fast feedback - Keep most tests cheap enough to run constantly Deterministic - Avoid sleeps, real clocks, network access, and ambient environment dependence Minimal setup - Prefer small helpers over deep fixture stacks High signal - Each failing test should point to one clear behaviour regression

Black-Box Test Packages

Prefer: Avoid: Use same-package tests only when you intentionally need access to unexported helpers and there is no better public seam. Default to _test packages.

File Organisation

Group tests by public API surface or behaviour Keep helper functions near the tests that use them unless broadly reused Prefer _test.go files named after the subject under test, such as service_test.go, handler_test.go, client_test.go Avoid giant catch-all files once a package grows

Fluxly profile Runtime and permissions are inferred by Fluxly static checks, not author declarations or runtime test results.
Domain
AI
Author-declared agents
No explicit declaration found; this is not inferred or tested compatibility
Static check
88 / 100 · heuristic scan, not runtime safety proof
Runtime evidence
Not run; no isolated runtime test evidence is currently recorded
Author / version / license
@tomevault-io · no license declared
Token usage
Lean
Setup complexity
Guided setup
External API key
Not required
Operating systems
Unspecified (assume cross-platform)
Runtime requirements
No explicit requirements detected
Detected file/system behavior
  • Read-only
  • Write / modify
  • Shell exec
  • Env read
Network behavior
Local-only
Install commands
None (reference only)

Heads up: Tool permissions are not declared; actual access depends on the runtime.

Output preview golang-testing-tomevault-io.preview
# fstest.MapFS Example

func TestLoadConfig(t *testing.T) {
    t.Parallel()

    files := fstest.MapFS{
        "config.json": {Data: []byte(`{"env":"test"}`)},
    }

    cfg, err := config.Load(files, "config.json")
    require.NoError(t, err)
    assert.Equal(t, "test", cfg.Env)
}

Discussion

Powered by GitHub Discussions. Sign in with GitHub to comment, react, or subscribe.