A Go library for loading YAML fixtures into a real test database, inspired by Ruby on Rails.
testfixtures is a Go library that loads YAML-based test data into a real database before each test run, similar to Ruby on Rails' fixture system. It solves the problem of setting up consistent database states for functional tests, eliminating the need for complex mocks and ensuring tests reflect production behavior. By wiping and reloading data automatically, it provides a clean slate for every test case.
Go developers building database-backed applications who need reliable, repeatable functional tests. It's particularly useful for teams practicing test-driven development (TDD) or those migrating from Rails-like ecosystems.
Developers choose testfixtures because it enables testing against real databases with minimal boilerplate, supports multiple SQL databases, and includes safety features to prevent accidental data loss. Its YAML format is human-readable, and the built-in dumper helps bootstrap fixtures from existing data.
Ruby on Rails like test fixtures for Go. Write tests against a real database
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Works with PostgreSQL, MySQL, SQLite, SQL Server, ClickHouse, and more via dialect configuration, making it versatile for multi-database projects.
Uses YAML files with automatic conversion for JSON, binary, and date/time columns, simplifying test data management without manual parsing.
Automatically wipes data and resets sequences, with checks like 'test' database name verification to prevent accidental production wipes.
Supports Go templates with custom functions and delimiters for generating fixture data dynamically, useful for complex test scenarios.
Default foreign key disabling requires SUPERUSER privileges, which can be a barrier in secure or managed environments unless using alternative methods like UseAlterConstraint.
For Google Spanner, interleaved tables require careful file ordering, and methods like Directory() are unsupported, adding setup overhead.
Reloading fixtures before each test can slow down test suites with large datasets, compared to mock-based or transaction-rollback approaches.