Overview
CompanyFlow includes a test suite for repositories and core functionality. Tests are written using Go’s built-in testing framework and require a test database.Prerequisites
Before running tests, ensure you have:- Go 1.24 or higher installed
- PostgreSQL test database configured
- All dependencies installed (
go mod download)
Test Database Setup
Running Tests
Run All Tests
Run the entire test suite:Run Specific Packages
Run with Coverage
Generate test coverage reports:Run Specific Tests
Run tests matching a pattern:Test Structure
CompanyFlow tests are organized by layer:Writing Tests
Repository Test Example
Here’s an example of how to write a repository test:repositories/company_repository_test.go
Service Test Example
Example service test with mocked repository:services/company_service_test.go
Handler Test Example
Example HTTP handler test:handlers/company_handler_test.go
Test Best Practices
Clean Up Test Data
Always clean up test data after tests:Use Table-Driven Tests
Test multiple scenarios efficiently:Use Test Fixtures
Create reusable test data:Use Subtests
Organize related tests:Integration Testing
Test API Endpoints
Test complete API workflows:Use Test Containers
For isolated integration tests, use Docker:Continuous Integration
GitHub Actions Example
.github/workflows/test.yml