Test Organization Patterns in Go

_test.go, external test packages

Use internal tests for unit testing unexported code and external tests for integration testing exported APIs.

Use internal test files (*_test.go) for unit tests within the same package and external test packages (*_test with a different package name) for integration tests or testing unexported symbols from outside the package.

// Internal test (same package, can access unexported symbols)
package mypkg

func TestInternal(t *testing.T) {
    // Access unexported helper() directly
    helper()
}

// External test (different package, only accesses exported symbols)
package mypkg_test

func TestExternal(t *testing.T) {
    // Can only call exported ExportedFunc()
    ExportedFunc()
}