customfit_ai_flutter_sdk 0.1.3
Flutter SDK for CustomFit.ai feature flags, A/B testing, and analytics. Real-time config updates with offline support and cross-platform compatibility.
Flutter SDK Testing Scripts
This directory contains comprehensive testing scripts for the CustomFit Flutter SDK. These Dart-based scripts provide detailed reporting, coverage analysis, performance testing, and benchmarking capabilities.
🚀 Quick Start
All scripts are written in Dart and can be run directly:
# Run unit tests
dart run tool/run_unit_tests.dart
# Generate coverage report
dart run tool/run_coverage.dart
# Run performance tests
dart run tool/run_performance.dart
# Run benchmarks
dart run tool/run_benchmarks.dart
📋 Available Scripts
1. run_unit_tests.dart - Unit Test Runner
Runs unit tests with module-level reporting and detailed statistics.
Features:
- Module-level test reporting (analytics/, client/, core/, etc.)
- Pass/fail counts per module
- Colored console output
- JUnit XML report generation
- JSON report generation
- Test filtering by module or tags
Usage:
# Run all unit tests
dart run tool/run_unit_tests.dart
# Run tests for specific module
dart run tool/run_unit_tests.dart --module analytics
# Generate JUnit report
dart run tool/run_unit_tests.dart --junit=test_results.xml
# Run with coverage
dart run tool/run_unit_tests.dart --coverage
# Verbose output
dart run tool/run_unit_tests.dart --verbose
Options:
-m, --module: Run tests for specific module only-t, --tags: Run tests with specific tags-c, --coverage: Generate coverage report-v, --verbose: Show detailed output--no-color: Disable colored output--fail-fast: Stop on first test failure-r, --reporter: Test reporter format (compact, expanded, json)--junit: Generate JUnit XML report at path--json-report: Generate JSON report at path
2. run_coverage.dart - Coverage Analysis
Generates detailed coverage reports with module-level breakdown.
Features:
- Module-level coverage percentages
- HTML report generation
- Coverage threshold enforcement
- Historical coverage tracking
- Uncovered files listing
- Auto-open HTML report in browser
Usage:
# Generate coverage report
dart run tool/run_coverage.dart
# Set minimum coverage threshold
dart run tool/run_coverage.dart --min-coverage=90
# Open HTML report automatically
dart run tool/run_coverage.dart --open
# Save report to file
dart run tool/run_coverage.dart --output=coverage_report.json
Options:
--min-coverage: Minimum coverage threshold (override config)-o, --open: Open HTML report in browser-f, --format: Output format (summary, detailed, lcov)-v, --verbose: Show detailed output--no-color: Disable colored output--output: Save report to file
3. run_performance.dart - Performance Testing
Runs stress tests and monitors performance metrics.
Features:
- Performance baseline tracking
- Regression detection
- Statistical analysis (mean, median, std dev, percentiles)
- Warmup runs before measurement
- Performance trend analysis
Usage:
# Run performance tests
dart run tool/run_performance.dart
# Update performance baseline
dart run tool/run_performance.dart --update-baseline
# Set custom regression threshold
dart run tool/run_performance.dart --threshold=100
# Test specific module
dart run tool/run_performance.dart --module=analytics
Options:
--update-baseline: Update performance baseline with current results-t, --threshold: Regression threshold in milliseconds-m, --module: Run performance tests for specific module only-v, --verbose: Show detailed output--no-color: Disable colored output--output: Save performance report to file
4. run_benchmarks.dart - Benchmark Suite
Measures performance of key SDK operations.
Features:
- Benchmarks for initialization, flag evaluation, event tracking, etc.
- Statistical analysis with standard deviation
- Throughput measurement (operations/second)
- Comparison with previous benchmarks
- Multiple output formats (JSON, CSV)
Usage:
# Run all benchmarks
dart run tool/run_benchmarks.dart
# Benchmark specific operation
dart run tool/run_benchmarks.dart --operation=flag_evaluation
# Custom iteration count
dart run tool/run_benchmarks.dart --iterations=50
# Export as CSV
dart run tool/run_benchmarks.dart --output=csv
Options:
-o, --operation: Specific operation to benchmark-i, --iterations: Number of iterations--compare: Compare with previous benchmark results-v, --verbose: Show detailed output--no-color: Disable colored output--output: Output format (console, json, csv, all)
⚙️ Configuration
All scripts use test_config.yaml for configuration. Key settings include:
# Test directories
test_directories:
- "test/unit"
- "test/stress"
# Coverage settings
coverage:
min_threshold: 85.0
exclude_files:
- "**/*.g.dart"
- "**/*.mocks.dart"
# Performance settings
performance:
regression_threshold_ms: 50
warmup_runs: 3
measurement_runs: 10
# Benchmark settings
benchmarks:
warmup_runs: 5
measurement_runs: 20
operations:
- "client_initialization"
- "flag_evaluation"
- "event_tracking"
📊 Output Examples
Unit Test Summary
Module Test Summary
────────────────────────────────────────────────────────────────────────────────
Module Total Passed Failed Skipped Pass Rate Time
────────────────────────────────────────────────────────────────────────────────
analytics 25 24 1 0 96.0% 2.3s
client 18 18 0 0 100.0% 1.5s
core 32 30 0 2 93.8% 3.1s
network 15 15 0 0 100.0% 1.2s
────────────────────────────────────────────────────────────────────────────────
TOTAL 90 87 1 2 96.7% 8.1s
Coverage Summary
Coverage Summary by Module
──────────────────────────────────────────────────────────────────────
Module Files Lines Covered Coverage Status
──────────────────────────────────────────────────────────────────────
analytics 8 420 395 94.0% ✓
client 5 280 271 96.8% ✓
core 12 650 585 90.0% ✓
network 6 320 272 85.0% ✓
──────────────────────────────────────────────────────────────────────
TOTAL 31 1670 1523 91.2% ✓
Performance Results
Performance Test Results
────────────────────────────────────────────────────────────────────────────────────────────────────
Test Name Mean Median StdDev Min Max P95 P99 Status
────────────────────────────────────────────────────────────────────────────────────────────────────
event_tracking_stress_test 125ms 120ms 15ms 105ms 180ms 165ms 175ms → ±5ms
cache_performance_stress_test 45ms 42ms 8ms 35ms 75ms 68ms 72ms ↓ -10ms (-18.2%)
network_health_monitor_stress_test 230ms 225ms 25ms 195ms 295ms 285ms 290ms ↑ +15ms (+7.0%)
🔧 Advanced Usage
Continuous Integration
Add to your CI pipeline:
# GitHub Actions example
- name: Run Unit Tests
run: dart run tool/run_unit_tests.dart --junit=results.xml
- name: Generate Coverage
run: dart run tool/run_coverage.dart --min-coverage=85
- name: Check Performance
run: dart run tool/run_performance.dart
- name: Upload Reports
uses: actions/upload-artifact@v2
with:
name: test-reports
path: |
results.xml
coverage/html/
tool/performance_report.json
Pre-commit Hook
Create .git/hooks/pre-commit:
#!/bin/bash
dart run tool/run_unit_tests.dart --fail-fast
if [ $? -ne 0 ]; then
echo "Tests failed. Commit aborted."
exit 1
fi
Custom Test Categories
Add custom test categories in test_config.yaml:
test_categories:
integration:
path_pattern: "test/integration/**/*_test.dart"
tags: ["integration"]
e2e:
path_pattern: "test/e2e/**/*_test.dart"
tags: ["e2e", "slow"]
🎯 Best Practices
- Regular Baseline Updates: Update performance baselines after significant changes
- Coverage Goals: Set module-specific coverage thresholds
- Performance Monitoring: Track performance trends over time
- Parallel Testing: Use parallel execution for faster test runs
- Test Organization: Keep tests organized by module for better reporting
🐛 Troubleshooting
Common Issues
-
"test_config.yaml not found"
- Ensure you're running scripts from the SDK root directory
- Check that
tool/test_config.yamlexists
-
"genhtml not found" (Coverage)
- Install lcov:
brew install lcov(macOS) orapt-get install lcov(Linux)
- Install lcov:
-
Performance test variations
- Increase warmup runs and measurement runs in config
- Run tests on a quiet system without other processes
-
Benchmark failures
- Ensure test dependencies are properly mocked
- Check that benchmark operations are isolated
📝 Contributing
When adding new test scripts:
- Follow the existing pattern for argument parsing
- Use the shared utilities in
src/ - Support both colored and plain output
- Include proper error handling
- Update this README with usage information
📄 License
These testing scripts are part of the CustomFit Flutter SDK and follow the same license terms.