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.
Complete YAML
Section titled “Complete YAML”name: iOS Unit Testsplatform: iosenvironment: 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' \ testEnhanced Version with Result Bundle
Section titled “Enhanced Version with Result Bundle”For better test reporting and diagnostics, add result bundle collection:
name: iOS Unit Testsplatform: iosenvironment: 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/**Key Points
Section titled “Key Points”- Workspace vs Project: Use
-workspaceif your app uses CocoaPods (requirespod install), otherwise use-project - Simulator Destination: The example uses
iPhone 15simulator; adjust the name to match your testing needs - Result Bundle: The
-resultBundlePathoption captures test results, logs, and screenshots for dashboard review - Test Artifacts: Collect result bundles as artifacts to preserve test reports after job completion
Test Schema Variations
Section titled “Test Schema Variations”For different test configurations:
# Run tests for a specific targetrun: | xcodebuild \ -workspace MyApp.xcworkspace \ -scheme MyApp \ -destination 'platform=iOS Simulator,name=iPhone 15' \ -only-testing: MyAppTests/TestClass \ test
# Run with verbose outputrun: | xcodebuild \ -workspace MyApp.xcworkspace \ -scheme MyApp \ -destination 'platform=iOS Simulator,name=iPhone 15' \ -verbose \ test
# Collect code coveragerun: | xcodebuild \ -workspace MyApp.xcworkspace \ -scheme MyApp \ -destination 'platform=iOS Simulator,name=iPhone 15' \ -enableCodeCoverage YES \ test