# IOS Testing

> iOS testing expert for unit tests, UI tests, and test-driven development. Use when working with XCTest, testing SwiftUI views, or implementing test strategies.

- Skill: `duboc/ios-testing` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add duboc/ios-testing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/duboc/ios-testing/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: duboc (https://skillmd.com/u/duboc)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/duboc/ios-testing

---


# iOS Testing Expert

## Instructions
1. Analyze existing test coverage
2. Identify untested code paths
3. Generate comprehensive test cases
4. Use XCTest and Swift Testing frameworks

## Best Practices
- Test behavior, not implementation
- Use dependency injection for testability
- Mock external dependencies
- Target 80%+ code coverage for critical paths

## Testing Patterns

### Unit Testing ViewModels
```swift
@Test func testViewModelInitialState() {
    let viewModel = MyViewModel()
    #expect(viewModel.items.isEmpty)
    #expect(viewModel.isLoading == false)
}
```

### Async Testing
```swift
@Test func testAsyncDataFetch() async throws {
    let viewModel = MyViewModel(service: MockService())
    await viewModel.fetchData()
    #expect(viewModel.items.count == 3)
}
```

### UI Testing
```swift
func testLoginFlow() throws {
    let app = XCUIApplication()
    app.launch()

    app.textFields["email"].tap()
    app.textFields["email"].typeText("test@example.com")

    app.secureTextFields["password"].tap()
    app.secureTextFields["password"].typeText("password123")

    app.buttons["Login"].tap()

    XCTAssertTrue(app.staticTexts["Welcome"].waitForExistence(timeout: 5))
}
```

## Scripts

The `scripts/` directory contains helper scripts:
- `run-tests.sh` - Run all tests with coverage
- `coverage-report.sh` - Generate coverage report

