Testing Overview
Terraphim employs a comprehensive testing strategy to ensure code quality, reliability, and maintainability across all components and platforms.
Testing Strategy
Multi-Level Testing
Terraphim implements a layered testing approach:
- Unit Tests: Individual function and module testing
- Integration Tests: Cross-component functionality testing
- End-to-End Tests: Full system workflow testing
- Performance Tests: Benchmarking and performance validation
- WASM Tests: WebAssembly compatibility testing
Testing Tools
Rust Testing
- cargo test: Standard Rust testing framework
- tokio::test: Async test support
- criterion: Performance benchmarking
- mockall: Mocking for unit tests
Frontend Testing
- Playwright: E2E testing for desktop and web applications
- Vitest: Unit testing for Svelte components
- TypeScript: Type checking and validation
Integration Testing
- Atomic Server: Real Atomic Data server integration
- Haystack: Document indexing and search validation
- Knowledge Graph: Graph construction and traversal testing
Unit Testing
Rust Unit Tests
Test Organization
crates/terraphim_service/
├── src/
│ ├── lib.rs
│ └── score/
│ ├── mod.rs
│ ├── bm25.rs
│ └── bm25_test.rs
└── tests/
├── integration_test.rs
└── e2e_test.rsBM25 Testing
Comprehensive tests for all BM25 variants:
Integration Testing
Service Integration Tests
async Atomic Data Integration
async Knowledge Graph Integration
MCP Server Integration Testing
The MCP (Model Context Protocol) server testing validates comprehensive functionality including knowledge graph integration:
async Knowledge Graph Term Verification
async End-to-End Testing
Playwright Tests
import { test, expect } from '@playwright/test';
test('search functionality', async ({ page }) => {
await page.goto('http://localhost:5173');
// Test search input
await page.fill('[data-testid="search-input"]', 'rust programming');
await page.click('[data-testid="search-button"]');
// Verify results
const results = await page.locator('[data-testid="search-result"]');
await expect(results).toHaveCount(3);
});Desktop Application Testing
test('desktop search with BM25', async ({ page }) => {
await page.goto('http://localhost:5174');
// Select BM25 scorer
await page.selectOption('[data-testid="scorer-select"]', 'bm25f');
// Perform search
await page.fill('[data-testid="search-input"]', 'test query');
await page.click('[data-testid="search-button"]');
// Verify BM25 results
const results = await page.locator('[data-testid="search-result"]');
await expect(results).toHaveCount(5);
});Atomic Server Integration
test('atomic server haystack integration', async ({ page }) => {
// Setup atomic server
await setupAtomicServer();
// Test document creation
await createTestDocument();
// Test search through atomic server
await page.goto('http://localhost:5173');
await page.fill('[data-testid="search-input"]', 'ATOMIC-test');
await page.click('[data-testid="search-button"]');
// Verify atomic document results
const atomicResults = await page.locator('[data-testid="atomic-result"]');
await expect(atomicResults).toHaveCount(1);
});Performance Testing
Benchmarking
use ;
criterion_group!;
criterion_main!;Throughput Testing
WASM Testing
WebAssembly Compatibility
Browser Testing
test('WASM autocomplete in browser', async ({ page }) => {
await page.goto('http://localhost:5173');
// Test WASM autocomplete
await page.fill('[data-testid="autocomplete-input"]', 'ru');
const suggestions = await page.locator('[data-testid="autocomplete-suggestion"]');
await expect(suggestions).toHaveCount(1);
await expect(suggestions.first()).toHaveText('rust');
});Test Data Management
Test Fixtures
Test Configuration
CI/CD Testing
GitHub Actions
name: Tests
on:
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Run unit tests
run: cargo test --all
- name: Run integration tests
run: cargo test --test integration
- name: Run E2E tests
run: yarn test:e2e
- name: Run performance tests
run: cargo benchTest Coverage
# Generate coverage report
# View coverage in browser
Testing Best Practices
Test Organization
- Unit tests: In same file as implementation
- Integration tests: In
tests/directory - E2E tests: In
desktop/tests/directory - Performance tests: In
benches/directory
Test Naming
Async Testing
async Error Testing
Mock Testing
use *;
Test Maintenance
Regular Updates
- Update test data when APIs change
- Maintain test coverage above 80%
- Review and update integration tests quarterly
- Performance test updates with major releases
Test Documentation
- Document complex test scenarios
- Explain test data requirements
- Document test environment setup
- Maintain test troubleshooting guides
Future Testing Enhancements
Planned Improvements
- Property-based testing: Using proptest for generative testing
- Fuzzing: Automated input testing for edge cases
- Load testing: High-volume performance validation
- Security testing: Vulnerability assessment
- Accessibility testing: UI accessibility validation