ios-testing
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+DesignSystemonly (neverData, never sibling features) - App target is the convergence point and owns
DependencyContainer, concrete coordinators, and Route Shell wiring Domainstays pure Swift and defines models plus repository,*Coordinating,ErrorRouting, andAppErrorcontractsDataowns SwiftData/network/sync/retry/background I/O and implements Domain protocols- 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 | arch- |
| 2 | Unit Testing Fundamentals | CRITICAL | unit- |
| 3 | Test Doubles & Isolation | HIGH | mock- |
| 4 | Async & Concurrency Testing | HIGH | async- |
| 5 | SwiftUI Testing | MEDIUM-HIGH | swiftui- |
| 6 | UI & Acceptance Testing | MEDIUM | ui- |
| 7 | Snapshot & Visual Testing | MEDIUM | snap- |
| 8 | Test Reliability & CI | LOW-MEDIUM | ci- |
Quick Reference
1. Test Architecture & Testability (CRITICAL)
arch-protocol-dependencies- Depend on protocols, not concrete typesarch-constructor-injection- Use constructor injection over service locatorsarch-test-target-separation- Separate unit and UI test targetsarch-testable-import- Use @testable import sparinglyarch-single-responsibility-tests- One assertion concept per testarch-arrange-act-assert- Structure tests as Arrange-Act-Assert
2. Unit Testing Fundamentals (CRITICAL)
unit-swift-testing-framework- Use Swift Testing over XCTest for new testsunit-parameterized-tests- Use parameterized tests for input variationsunit-descriptive-test-names- Name tests after the behavior they verifyunit-expect-over-assert- Use #expect and #require over XCTAssertunit-require-preconditions- Use #require for test preconditionsunit-test-suites- Organize related tests into suitesunit-test-tags- Use tags to categorize cross-cutting tests
3. Test Doubles & Isolation (HIGH)
mock-protocol-based-mocks- Create mocks from protocols, not subclassesmock-spy-for-verification- Use spies to verify interactionsmock-stub-return-values- Use stubs for deterministic return valuesmock-avoid-over-mocking- Avoid mocking value types and simple logicmock-fake-for-integration- Use in-memory fakes for integration testsmock-dependency-container- Use a dependency container for test configuration
4. Async & Concurrency Testing (HIGH)
async-await-directly- Await async functions directly in testsasync-confirmation- Use confirmation() for callback-based APIsasync-mainactor-isolation- Test MainActor-isolated code on MainActorasync-actor-testing- Test actor state through async interfaceasync-task-cancellation- Test task cancellation paths explicitly
5. SwiftUI Testing (MEDIUM-HIGH)
swiftui-test-observable-models- Test @Observable models as plain objectsswiftui-environment-injection- Inject environment dependencies for testsswiftui-preview-as-test- Use previews as visual smoke testsswiftui-view-model-extraction- Extract logic from views into testable modelsswiftui-binding-testing- Test binding behavior with @Bindable
6. UI & Acceptance Testing (MEDIUM)
ui-accessibility-identifiers- Use accessibility identifiers for element queriesui-page-object-pattern- Encapsulate screens in page objectsui-launch-arguments- Configure test state via launch argumentsui-wait-for-elements- Wait for elements instead of using sleep()ui-test-user-journeys- Test complete user journeys, not individual screensui-reset-state-between-tests- Reset app state between UI tests
7. Snapshot & Visual Testing (MEDIUM)
snap-swift-snapshot-testing- Use swift-snapshot-testing for visual regressionsnap-device-matrix- Snapshot across device sizes and traitssnap-named-references- Use named snapshot references for claritysnap-inline-snapshots- Use inline snapshots for non-image assertions
8. Test Reliability & CI (LOW-MEDIUM)
ci-test-plans- Use Xcode Test Plans for environment configurationsci-parallel-execution- Enable parallel test executionci-flaky-test-quarantine- Quarantine flaky tests instead of disabling themci-deterministic-test-data- Use deterministic test data over random generationci-coverage-thresholds- Set coverage thresholds for critical paths
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 |
More from pproenca/dot-skills
zod
Zod schema validation best practices for type safety, parsing, and error handling. This skill should be used when defining z.object schemas, using z.string validations, safeParse, or z.infer. This skill does NOT cover React Hook Form integration patterns (use react-hook-form skill) or OpenAPI client generation (use orval skill).
2.0Kclean-architecture
Clean Architecture principles and best practices from Robert C. Martin's book. This skill should be used when designing software systems, reviewing code structure, or refactoring applications to achieve better separation of concerns. Triggers on tasks involving layers, boundaries, dependency direction, entities, use cases, or system architecture.
1.4Kemilkowal-animations
Emil Kowalski's animation best practices for web interfaces. Use when writing, reviewing, or implementing animations in React, CSS, or Framer Motion. Triggers on tasks involving transitions, easing, gestures, toasts, drawers, or motion.
917vitest
Vitest testing framework patterns for test setup, async testing, mocking with vi.*, snapshots, and test performance (formerly test-vitest). This skill should be used when writing or debugging Vitest tests. This skill does NOT cover TDD methodology (use test-tdd skill), API mocking with MSW (use test-msw skill), or Jest-specific APIs.
906typescript
This skill should be used when the user asks to "optimize TypeScript performance", "speed up tsc compilation", "configure tsconfig.json", "fix type errors", "improve async patterns", or encounters TS errors (TS2322, TS2339, "is not assignable to"). Also triggers on .ts, .tsx, .d.ts file work involving type definitions, module organization, or memory management. Does NOT cover TypeScript basics, framework-specific patterns, or testing.
820nuqs
nuqs (type-safe URL query state) best practices for Next.js applications. This skill should be used when writing, reviewing, or refactoring code that uses nuqs for URL state management. Triggers on tasks involving useQueryState, useQueryStates, search params, URL state, query parameters, nuqs parsers, or Next.js routing with state.
734