A mock SQL driver for Go that simulates database behavior in tests without requiring a real database connection.
sqlmock is a mock SQL driver library for Go that simulates database driver behavior in tests. It allows developers to test database interactions—such as queries, transactions, and prepared statements—without needing an actual database connection, enabling faster and more isolated unit tests.
Go developers writing applications that interact with SQL databases and who want to implement thorough, isolated unit tests for their database layer without external dependencies.
Developers choose sqlmock because it integrates seamlessly with Go's standard database/sql package, requires no changes to production code, provides precise control over mock behavior, and supports advanced features like custom query matchers and argument matching for complex types.
Sql mock driver for golang to test database interactions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Simulates SQL driver behavior entirely in memory, enabling fast, isolated unit tests without the overhead of a real database connection, as emphasized in the 'No Database Required' feature.
Works with Go's standard database/sql package without requiring any modifications to production code, allowing easy adoption in existing projects.
Handles multiple connections and concurrent operations safely, making it suitable for testing race conditions and concurrent database access patterns.
Provides a customizable QueryMatcher interface for sophisticated SQL validation, such as regex or equality matching, beyond basic string comparison.
Past updates like v1.2.0 introduced breaking changes by altering sqlmock.Rows from an interface to a struct, which can break existing test suites and requires careful migration.
The README states the project is looking for maintainers, indicating potential lack of active development or support, which could lead to stagnation or unresolved issues.
Setting up precise mock expectations for each SQL query and transaction can be verbose and error-prone, increasing test code complexity and maintenance burden.