Skip to content

Unit Tests

Run your iOS unit tests using xcodebuild with result bundles. This recipe captures test results, logs, and diagnostics that appear in the RunnerHub dashboard.

name: iOS Unit Tests
platform: ios
environment:
xcode: "16.4"
triggers:
- push
- pull_request
steps:
- name: Install pods
run: pod install
- name: Run tests
run: |
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
test

For better test reporting and diagnostics, add result bundle collection:

name: iOS Unit Tests
platform: ios
environment:
xcode: "16.4"
triggers:
- push
- pull_request
steps:
- name: Install pods
run: pod install
- name: Run tests
run: |
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-resultBundlePath build/test-results \
test
artifacts:
- build/test-results/**
  • Workspace vs Project: Use -workspace if your app uses CocoaPods (requires pod install), otherwise use -project
  • Simulator Destination: The example uses iPhone 15 simulator; adjust the name to match your testing needs
  • Result Bundle: The -resultBundlePath option captures test results, logs, and screenshots for dashboard review
  • Test Artifacts: Collect result bundles as artifacts to preserve test reports after job completion

For different test configurations:

# Run tests for a specific target
run: |
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-only-testing: MyAppTests/TestClass \
test
# Run with verbose output
run: |
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-verbose \
test
# Collect code coverage
run: |
xcodebuild \
-workspace MyApp.xcworkspace \
-scheme MyApp \
-destination 'platform=iOS Simulator,name=iPhone 15' \
-enableCodeCoverage YES \
test