LocalData/Documentation/Testing.md
Matt Bruce 9a9889b8a0 Update Audit, Helpers, Services + tests + docs
Summary:
- Sources: Audit, Helpers, Services
- Tests: StorageCatalogTests.swift
- Docs: Design, Migration, Testing
- Added symbols: struct MyNewKey, func setupSession, func handleReceivedContext, class SessionDelegateProxy, func session, func sessionDidBecomeInactive (+2 more)

Stats:
- 10 files changed, 181 insertions(+), 1 deletion(-)
2026-01-18 14:53:28 -06:00

34 lines
1.2 KiB
Markdown

# LocalData Testing Strategy
## Goal
To ensure high reliability for data persistence, security, and migration across all supported platforms (iOS and watchOS).
## Test Suites
### Unit Tests (`Tests/LocalDataTests/`)
- **LocalDataTests.swift**: Core round-trip tests for each storage domain (UserDefaults, FileSystem).
- **KeychainHelperTests.swift**: Verification of Keychain API interactions (add, update, delete, exists).
- **EncryptionHelperTests.swift**: Round-trip tests for AES and ChaCha20 encryption/decryption with various key derivation methods.
- **StorageCatalogTests.swift**: Validation of catalog registration, duplicate detection, and missing description checks.
## Key Testing Patterns
### 1. Domain Round-Trips
Always test the full cycle: `set` -> `get` (compare) -> `remove` -> `get` (expect `notFound`).
### 2. Migration Tests
Simulate legacy data by writing to a "legacy" key first, then verifying that the "modern" key can retrieve and consolidate that data.
### 3. Error Handling
Verify that the correct `StorageError` is thrown for:
- `notFound`
- `unregisteredKey`
- `dataTooLargeForSync`
- Domain-specific failures (e.g., Keychain errors)
## Running Tests
Run all tests from the package root:
```bash
swift test
```