Testing & Quality Assurance
Comprehensive testing infrastructure and practices.
Test Suite Overview
HANA CLI includes over 300 tests across multiple categories.
For detailed coverage analysis, see: TEST_COVERAGE_ANALYSIS.md
Unit Tests
Testing individual functions and modules in isolation.
Location: tests/unit/
Coverage Areas:
- Utility functions (formatting, validation, parsing)
- Database operation builders
- Error handling
- Data transformation
Example:
npm test -- tests/unit/utils/formatting.jsIntegration Tests
Testing how components work together.
Location: tests/integration/
Coverage Areas:
- Command workflows (import → export → compare)
- Database connections
- File I/O operations
- Error recovery
Example:
npm test -- tests/integration/import-export.jsEnd-to-End Tests
Testing complete workflows through the CLI.
Location: tests/e2e/
Coverage Areas:
- Full command execution
- Exit codes
- Console output
- Error messages
Example:
npm test -- tests/e2e/import.e2e.jsRunning Tests
All Tests
npm testSpecific Test File
npm test -- tests/unit/utils/validation.jsWatch Mode
npm test -- --watchWith Coverage
npm test -- --coverageUsing Mocks
Tests use mocked database connections:
const mockDb = {
execute: jest.fn().mockResolvedValue({
rows: [{ id: 1, name: 'Test' }]
})
}Test Assertions
Using Jest matchers:
expect(result).toBeDefined()
expect(result).toEqual(expected)
expect(result).not.toThrow()
expect(mockDb.execute).toHaveBeenCalled()Coverage Goals
Target metrics:
- Line Coverage: 85%+
- Branch Coverage: 80%+
- Function Coverage: 90%+
Currently tracked in: TEST_COVERAGE_COMPLETION_SUMMARY.md
Performance Benchmarks
Startup time benchmarks:
- Before optimization: 2.2 seconds
- After optimization: 700ms
- Improvement: ~7x faster
CI/CD Testing
Automated testing on every commit:
- Run full test suite
- Generate coverage reports
- Block merging if tests fail
- Report to pull request
Testing Best Practices
Arrange-Act-Assert Pattern
javascript// Arrange const input = { name: 'test' } // Act const result = processData(input) // Assert expect(result).toBeDefined()Descriptive Test Names
javascriptit('should throw error when file does not exist', () => { // test code })Single Responsibility
- Test one thing per test
- Clear expected behavior
- Easy to debug when failing
Mock External Dependencies
- Database calls
- File system operations
- Network requests
Use Fixtures
- Prepare test data
- Reusable across tests
- Easier maintenance
Debugging Tests
Verbose Output
npm test -- --verboseDebug Single Test
node --inspect-brk node_modules/.bin/jest tests/unit/specific-test.jsThen open chrome://inspect in Chrome DevTools.
Print Debug Info
console.log('Current state:', { input, output })Writing New Tests
For new commands:
- Create test file:
tests/unit/commands/new-command.js - Test builder function
- Test handler function (mocked)
- Test error cases
- Add integration test:
tests/integration/new-command.js
Example template:
describe('NewCommand', () => {
it('should accept required options', () => {
// test code
})
it('should throw error without options', () => {
// test code
})
it('should execute handler', async () => {
// test code
})
})Test Data
Sample test data files in tests/fixtures/:
- CSV files for import testing
- Excel files for format testing
- SQL scripts for schema testing
- Sample JSON for output validation
Performance Profiling
Identify bottlenecks:
node --prof app/import.js
node --prof-process isolate-*.log > profile.txtContinuous Monitoring
Tools in use:
- Jest for test execution
- Coverage reports showing gaps
- Benchmarks tracking performance
- GitHub Actions for CI/CD
See Also:
