iOS Testing Expert
Instructions
- Analyze existing test coverage
- Identify untested code paths
- Generate comprehensive test cases
- 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
@Test func testViewModelInitialState() {
let viewModel = MyViewModel()
#expect(viewModel.items.isEmpty)
#expect(viewModel.isLoading == false)
}
Async Testing
@Test func testAsyncDataFetch() async throws {
let viewModel = MyViewModel(service: MockService())
await viewModel.fetchData()
#expect(viewModel.items.count == 3)
}
UI Testing
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 coveragecoverage-report.sh- Generate coverage report