specta#
Composable Testing for Go
specta is a Go testing library that emphasizes composition and reuse through matchers and test data factories. Build reusable test components instead of duplicating assertions.
Quick Links#
Key Features#
- Composable Matchers - Build complex assertions from simple, reusable pieces
- Type-Safe Factories - Generate deterministic test data with sensible defaults
- Partial Matching - Assert only what matters, avoid brittle tests
- Code Generation - Automatically generate matchers and factories for your types
- Property-Based Testing - Use factories and matchers for powerful property-based tests
Quick Example#
// Instead of brittle assertions like:
if user.Name != "Alice" || user.Email != "alice@example.com" {
t.Fatal("user mismatch")
}
// Write composable, expressive matchers:
specta.AssertThat(t, user, MatchUser().
WithName(specta.Equal("Alice")).
WithEmail(specta.Contains("example.com")))