Testing Guide
Comprehensive testing with 338+ tests.Complete testing documents in your project: testing-documents.md
Test Suite Overview
Unit Tests
251 tests - ViewModels, repositories, clients
Integration Tests
47 tests - Component interaction
Snapshot Tests
12 tests - UI rendering verification
UI Tests
28 tests - End-to-end flows
Run Tests
- Xcode
- Command Line
Coverage Goals
| Module | Target | Status |
|---|---|---|
| Core | 96%+ | ✅ |
| Networking | 93%+ | ✅ |
| Storage | 88%+ | ✅ |
| Auth | 87%+ | ✅ |
| AI | 91%+ | ✅ |
| Payments | 82%+ | ✅ |
| FeatureChat | 78%+ | ✅ |
| Overall | 85-90% | ✅ CI Enforced |
Writing Tests
Unit Test Example
Integration Test Example
UI Test Example
CI/CD Integration
Automated Testing
Tests run automatically on:- ✅ Every push to
main/develop - ✅ All pull requests
- ✅ Coverage gate: Fails if < 85%
- ✅ SwiftLint enforcement
Coverage Reports
- Automatic PR comments with coverage stats
- Weekly comprehensive reports
- HTML reports with detailed breakdowns
- Issue creation for low coverage modules
Test Organization
Best Practices
What to Test
What to Test
Do test:
- ✅ ViewModels (business logic)
- ✅ Repositories (data access)
- ✅ Clients (external services)
- ✅ Error scenarios
- ✅ Edge cases
- ❌ SwiftUI Views (snapshot instead)
- ❌ Third-party libraries
- ❌ Framework code
Test Structure
Test Structure
- Use Arrange-Act-Assert pattern
- One assertion per test (when possible)
- Clear test names (testSendMessage_WhenOffline_ShowsError)
- Mock external dependencies
- Test in isolation
Mock Guidelines
Mock Guidelines
- Protocol-based mocking
- Track call counts
- Configurable behavior
- Avoid over-mocking
- Use real objects when simple
Coverage Measurement
View Complete Guide
View Complete Testing Guide
Complete guide with examples, patterns, and best practices
Troubleshooting
Tests fail on CI but pass locally
Tests fail on CI but pass locally
- Check iOS version match
- Verify simulator name
- Clear derived data
- Check for timing issues
Coverage lower than expected
Coverage lower than expected
- Run with —coverage flag
- Check for untested branches
- Add error scenario tests
- Test async code properly
UI tests flaky
UI tests flaky
- Add explicit waits
- Use accessibility identifiers
- Avoid animations in tests
- Check for race conditions
