install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/ios-testing" ~/.claude/skills/comeonoliver-skillshub-ios-testing && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/ios-testing/SKILL.mdsource content
iOS Testing Best Practices
Comprehensive testing guide for iOS and Swift applications, written at principal engineer level. Contains 44 rules across 8 categories, prioritized by impact to guide test architecture decisions, test authoring patterns, and CI infrastructure.
Clinic Architecture Contract (iOS 26 / Swift 6.2)
All guidance in this skill assumes the clinic modular MVVM-C architecture:
- Feature modules import
+Domain
only (neverDesignSystem
, never sibling features)Data - App target is the convergence point and owns
, concrete coordinators, and Route Shell wiringDependencyContainer
stays pure Swift and defines models plus repository,Domain
,*Coordinating
, andErrorRouting
contractsAppError
owns SwiftData/network/sync/retry/background I/O and implements Domain protocolsData- Read/write flow defaults to stale-while-revalidate reads and optimistic queued writes
- ViewModels call repository protocols directly (no default use-case/interactor layer)
When to Apply
Reference these guidelines when:
- Writing new unit tests or UI tests for iOS apps
- Designing testable architecture with dependency injection
- Testing async/await, actors, and Combine publishers
- Setting up snapshot testing or visual regression suites
- Configuring CI pipelines, test plans, and parallel execution
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Test Architecture & Testability | CRITICAL | |
| 2 | Unit Testing Fundamentals | CRITICAL | |
| 3 | Test Doubles & Isolation | HIGH | |
| 4 | Async & Concurrency Testing | HIGH | |
| 5 | SwiftUI Testing | MEDIUM-HIGH | |
| 6 | UI & Acceptance Testing | MEDIUM | |
| 7 | Snapshot & Visual Testing | MEDIUM | |
| 8 | Test Reliability & CI | LOW-MEDIUM | |
Quick Reference
1. Test Architecture & Testability (CRITICAL)
- Depend on protocols, not concrete typesarch-protocol-dependencies
- Use constructor injection over service locatorsarch-constructor-injection
- Separate unit and UI test targetsarch-test-target-separation
- Use @testable import sparinglyarch-testable-import
- One assertion concept per testarch-single-responsibility-tests
- Structure tests as Arrange-Act-Assertarch-arrange-act-assert
2. Unit Testing Fundamentals (CRITICAL)
- Use Swift Testing over XCTest for new testsunit-swift-testing-framework
- Use parameterized tests for input variationsunit-parameterized-tests
- Name tests after the behavior they verifyunit-descriptive-test-names
- Use #expect and #require over XCTAssertunit-expect-over-assert
- Use #require for test preconditionsunit-require-preconditions
- Organize related tests into suitesunit-test-suites
- Use tags to categorize cross-cutting testsunit-test-tags
3. Test Doubles & Isolation (HIGH)
- Create mocks from protocols, not subclassesmock-protocol-based-mocks
- Use spies to verify interactionsmock-spy-for-verification
- Use stubs for deterministic return valuesmock-stub-return-values
- Avoid mocking value types and simple logicmock-avoid-over-mocking
- Use in-memory fakes for integration testsmock-fake-for-integration
- Use a dependency container for test configurationmock-dependency-container
4. Async & Concurrency Testing (HIGH)
- Await async functions directly in testsasync-await-directly
- Use confirmation() for callback-based APIsasync-confirmation
- Test MainActor-isolated code on MainActorasync-mainactor-isolation
- Test actor state through async interfaceasync-actor-testing
- Test task cancellation paths explicitlyasync-task-cancellation
5. SwiftUI Testing (MEDIUM-HIGH)
- Test @Observable models as plain objectsswiftui-test-observable-models
- Inject environment dependencies for testsswiftui-environment-injection
- Use previews as visual smoke testsswiftui-preview-as-test
- Extract logic from views into testable modelsswiftui-view-model-extraction
- Test binding behavior with @Bindableswiftui-binding-testing
6. UI & Acceptance Testing (MEDIUM)
- Use accessibility identifiers for element queriesui-accessibility-identifiers
- Encapsulate screens in page objectsui-page-object-pattern
- Configure test state via launch argumentsui-launch-arguments
- Wait for elements instead of using sleep()ui-wait-for-elements
- Test complete user journeys, not individual screensui-test-user-journeys
- Reset app state between UI testsui-reset-state-between-tests
7. Snapshot & Visual Testing (MEDIUM)
- Use swift-snapshot-testing for visual regressionsnap-swift-snapshot-testing
- Snapshot across device sizes and traitssnap-device-matrix
- Use named snapshot references for claritysnap-named-references
- Use inline snapshots for non-image assertionssnap-inline-snapshots
8. Test Reliability & CI (LOW-MEDIUM)
- Use Xcode Test Plans for environment configurationsci-test-plans
- Enable parallel test executionci-parallel-execution
- Quarantine flaky tests instead of disabling themci-flaky-test-quarantine
- Use deterministic test data over random generationci-deterministic-test-data
- Set coverage thresholds for critical pathsci-coverage-thresholds
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |