Development
Testing
Testing Guide
Comprehensive testing instructions for both the C++ core and React UI components of MLGraph.
Testing Philosophy
- Never reduce test data sizes - The system is designed for billions of vectors
- Fix failing tests immediately - Don't skip or disable tests
- Use real operations over mocks when possible
- 100% test pass rate is mandatory - No exceptions
C++ Core Tests
The project contains 206+ test files organized by component in the tests/ directory.
Running Tests
# All Tests (Parallel) cd build ./scripts/test/run_parallel_tests.sh # OR ctest -j8 --output-on-failure --timeout 120 # Specific Test Categories ctest -R "^test_" -j8 # Unit tests only ctest -R "integration" -j8 # Integration tests ctest -R "distributed" -j8 # Distributed system tests # Individual Tests ./test_simple ./test_distributed_index_manager ./test_auth_system_comprehensive
Test Categories
Core Functionality
- test_simple
- test_index_manager_service
- test_vector_operations
- test_search_engine_service
Distributed System
- test_distributed_index_manager
- test_distributed_fault_tolerance
- test_distributed_replication
- test_chaos_engineering
Authentication & Security
- test_auth_system_comprehensive
- test_auth_backends
- test_oauth_integration
- test_tls_communication
Performance
- test_performance_benchmarks
- benchmark_cli
React UI Tests
UI tests use Vitest as the test runner, React Testing Library for component testing, and MSW (Mock Service Worker) for API mocking.
cd ui/mlgraph-ui # All Tests npm test # Watch mode npm test -- --run # Single run npm test -- --coverage # With coverage # Specific Test Files npm test Dashboard.test.tsx # E2E Tests (Playwright) npm run test:e2e npm run test:e2e:ui # With UI
Test Statistics
888
Total Tests
97.5%+
Pass Rate
400+
Component Tests
300+
Page Tests
Coverage Reports
C++ Coverage (macOS with LLVM)
# Build with coverage
cmake .. -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-fprofile-instr-generate -fcoverage-mapping"
make -j8
# Run tests
LLVM_PROFILE_FILE="mlgraph-%p.profraw" ctest -j8
# Generate report
xcrun llvm-profdata merge -sparse mlgraph-*.profraw -o mlgraph.profdata
xcrun llvm-cov report ./test_simple -instr-profile=mlgraph.profdataUI Coverage
cd ui/mlgraph-ui npm test -- --run --coverage # View HTML report open coverage/index.html
Coverage Targets
80%+
Statements
70%+
Branches
80%+
Functions
80%+
Lines
Debugging Failed Tests
# C++ test debugging ctest -V -R test_name # Verbose output lldb ./test_failing # With debugger valgrind --leak-check=full ./test_simple # Memory check # React test debugging npm test -- --inspect npm test -- --bail # Stop on first failure
Troubleshooting
Test timeout
Increase timeout: set_tests_properties(test PROPERTIES TIMEOUT 300)
Flaky tests
Add proper waits: waitFor(() => expect(...))
Parallel test failures
Check for shared resources; use unique ports/files per test