Run Tests
Execute tests for the iOS project.
Test Commands
Run All Tests
xcodebuild test \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-resultBundlePath TestResults.xcresult
Run Specific Test Target
xcodebuild test \
-scheme MyApp \
-only-testing:MyAppTests \
-destination 'platform=iOS Simulator,name=iPhone 15'
Run Specific Test Class
xcodebuild test \
-scheme MyApp \
-only-testing:MyAppTests/MyViewModelTests \
-destination 'platform=iOS Simulator,name=iPhone 15'
Run Specific Test Method
xcodebuild test \
-scheme MyApp \
-only-testing:MyAppTests/MyViewModelTests/testInitialState \
-destination 'platform=iOS Simulator,name=iPhone 15'
Swift Package Tests
swift test
Test Coverage
Generate Coverage Report
xcodebuild test \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-enableCodeCoverage YES
View Coverage
xcrun xccov view --report TestResults.xcresult
Parallel Testing
xcodebuild test \
-scheme MyApp \
-parallel-testing-enabled YES \
-parallel-testing-worker-count 4 \
-destination 'platform=iOS Simulator,name=iPhone 15'
Workflow
- Identify test targets (unit tests, UI tests)
- Run unit tests first (faster)
- Run UI tests if unit tests pass
- Report results with coverage