3.4 KiB
3.4 KiB
XCUITest Authoring Guide
This guide documents the current SportsTime UI test foundation and how to add new tests safely.
Current Foundation
Layout
- Test target:
SportsTimeUITests - Base setup/helpers:
SportsTimeUITests/Framework/BaseUITestCase.swift - Page objects + shared flows:
SportsTimeUITests/Framework/Screens.swift - Suite files:
SportsTimeUITests/Tests/*.swift - Legacy mixed tests:
SportsTimeUITests/SportsTimeUITests.swiftandSportsTimeUITests/SportsTimeUITestsLaunchTests.swift
Existing Suite Coverage
AppLaunchTestsHomeTestsTabNavigationTestsScheduleTestsTripWizardFlowTestsTripOptionsTestsTripSavingTestsProgressTestsSettingsTestsAccessibilityTestsStabilityTests
Key Conventions
- Inherit from
BaseUITestCase. - Use
@MainActortest methods. - Prefer page-object actions over direct element taps.
- Prefer existing high-level flows (
TestFlows.planDateRangeTrip,TestFlows.planAndSelectFirstTrip) for shared setup. - Use deterministic selectors with accessibility identifiers.
- Use
waitForExistenceOrFailandwaitUntilHittableinstead of arbitrary sleeps.
Adding a New UI Test
- Pick the closest existing suite in
SportsTimeUITests/Tests/. - If none fits, create a new suite using
XCUITestSuiteTemplate.swift. - Add/extend page-object methods in
Screens.swiftbefore writing raw element code. - Reuse
TestFlowswhen setup overlaps existing end-to-end flows. - Keep assertion messages explicit and behavior-focused.
- Capture screenshot(s) for key milestone state in longer flows.
- Run targeted tests, then full UI tests.
When to Edit Screens.swift
Edit page objects when:
- A new screen element needs a stable selector.
- The interaction is reused across multiple tests.
- The flow can be standardized (especially wizard planning flow).
Do not add one-off test-only branching logic unless it removes a real flake.
Running Tests
Fast Loop (single test)
xcodebuild test-without-building \
-project SportsTime.xcodeproj \
-scheme SportsTime \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
-parallel-testing-enabled NO \
-only-testing:SportsTimeUITests/TripWizardFlowTests/testF026_DateRangeSelection
Per Class
xcodebuild test-without-building \
-project SportsTime.xcodeproj \
-scheme SportsTime \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
-parallel-testing-enabled NO \
-only-testing:SportsTimeUITests/TripOptionsTests
Full UI Suite
xcodebuild test-without-building \
-project SportsTime.xcodeproj \
-scheme SportsTime \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
-parallel-testing-enabled NO \
-only-testing:SportsTimeUITests
Full Scheme Validation (unit + UI)
xcodebuild test-without-building \
-project SportsTime.xcodeproj \
-scheme SportsTime \
-destination 'platform=iOS Simulator,name=iPhone 17,OS=26.2' \
-parallel-testing-enabled NO
Flake Prevention Notes
- Keep simulator orientation consistent (portrait baseline from
BaseUITestCase). - For wizard date selection, navigate by month/year first and use day-cell fallback when specific IDs are unavailable.
- For cross-season planning tests, prefer deterministic fallback sports if selected sport has no viable schedule for current test data.
- Increase waits only where planning computation is the actual bottleneck.