Running Tests
Run All Tests
Execute all tests in the project:Run Tests with Verbose Output
Run Specific Package Tests
Run Individual Test Functions
Run Tests with Coverage
Test Structure
QueryBox tests are organized alongside the source code:Writing Tests
Basic Test Structure
Follow Go’s standard test conventions:Table-Driven Tests
Use table-driven tests for multiple test cases:Testing with Context
Many QueryBox functions acceptcontext.Context for cancellation:
Testing Cleanup and Shutdown
Test that resources are properly cleaned up:Mocking Dependencies
Use dependency injection for testability:Plugin Testing
Testing Plugin Logic
Plugin tests typically focus on:- DSN/connection string parsing
- Query execution logic
- Result formatting
- Error handling
mysql_test.go:
Integration Tests
Some plugin tests may require actual database connections. Use environment variables or skip conditions:Platform-Specific Tests
Use build tags for platform-specific tests:Testing Best Practices
1. Use Descriptive Test Names
2. Test Error Cases
3. Use t.Helper() for Test Utilities
4. Clean Up Resources
5. Skip Unavailable Tests
Continuous Integration
QueryBox tests should pass in CI environments. Ensure your tests:- Don’t rely on external services (or skip gracefully)
- Don’t require specific file paths (use
t.TempDir()) - Are platform-agnostic (or use build tags)
- Complete within reasonable time limits
Test Coverage Goals
Aim for:- Core services: 80%+ coverage
- Plugin SDK: 90%+ coverage
- Individual plugins: 70%+ coverage
- Critical paths: 100% coverage (authentication, credential storage, query execution)
Debugging Tests
Run with Race Detector
Run with Memory Sanitizer
Enable Verbose Logging
Next Steps
Contributing Overview
Return to the contributing guide
Building
Learn how to build the application