An integration test verifies behavior across a program and external systems or components. In Go, a realistic test can connect a service to a unique SQLite test database, exercise its public method, and check both successful behavior and database-driven failures. section 10.0 section 10.2.3
Testing a database-backed service
Create a test database with DialTestDB(t), construct a Shortener with that database, and call Shorten using t.Context(). First verify that a link returns its expected key. Then submit the same link again and require link.ErrConflict rather than exposing SQLite's constraint error. Running the test initially reveals the leaking driver error; errors.As can identify that low-level error so the service can return an application-specific one. section 10.2.3
A practical integration test emphasizes:
- Using a unique test database for isolation between tests. section 10.2.3
- Passing t.Context() so cancellation follows the test lifetime. section 10.2.3
- Checking application-level errors instead of coupling callers to database-driver details. section 10.2.3 section 10.6
- Cleaning up resources with T.Cleanup or TB.Cleanup before the test finishes. section 10.6






























