Rewrite all UI tests following fail-fast TEST_RULES patterns
Rewrote 60+ test files to follow honeydue-style test guidelines:
- defaultTimeout=2s, navigationTimeout=5s — fail fast, no long waits
- No coordinate taps (except onboarding paged TabView swipes)
- No sleep(), no retry loops
- No guard...else { return } silent passes — XCTFail everywhere
- All elements by accessibility ID via UITestID constants
- Screen objects for all navigation/actions/assertions
- One logical assertion per test method
Added missing accessibility identifiers to app views:
- MonthView.swift: added AccessibilityID.MonthView.grid to ScrollView
- YearView.swift: added AccessibilityID.YearView.heatmap to ScrollView
Framework rewrites:
- BaseUITestCase: added session ID, localeArguments, extraLaunchArguments
- WaitHelpers: waitForExistenceOrFail, waitUntilHittableOrFail,
waitForNonExistence, scrollIntoView, forceTap
- All 7 screen objects rewritten with fail-fast semantics
- TEST_RULES.md added with non-negotiable rules
Known remaining issues:
- OnboardingTests: paged TabView swipes unreliable on iOS 26 simulator
- SettingsLegalLinksTests: EULA/Privacy buttons too deep in DEBUG scroll
- Customization horizontal picker scrolling needs further tuning
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
// Tests iOS
|
||||
//
|
||||
// Base class for all UI tests. Handles launch arguments,
|
||||
// state reset, screenshot capture on failure, and parallel
|
||||
// test isolation via per-session data sandboxing.
|
||||
// parallel test isolation, and screenshot capture on failure.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@@ -13,6 +12,11 @@ class BaseUITestCase: XCTestCase {
|
||||
|
||||
var app: XCUIApplication!
|
||||
|
||||
/// Element on current screen — if it's not there in 2s, the app is broken
|
||||
let defaultTimeout: TimeInterval = 2
|
||||
/// Screen transitions, tab switches
|
||||
let navigationTimeout: TimeInterval = 5
|
||||
|
||||
// MARK: - Parallel Test Isolation
|
||||
|
||||
/// Unique session ID for this test class instance.
|
||||
@@ -34,13 +38,10 @@ class BaseUITestCase: XCTestCase {
|
||||
/// Whether to force the trial to be expired. Default: false.
|
||||
var expireTrial: Bool { false }
|
||||
|
||||
/// Override to change the test locale/language.
|
||||
/// Default: English (US). Locale tests override this instead of setUp().
|
||||
/// Override to change the test locale/language. Default: English (US).
|
||||
var localeArguments: [String] { ["-AppleLanguages", "(en)", "-AppleLocale", "en_US"] }
|
||||
|
||||
/// Extra launch arguments for tests needing special settings
|
||||
/// (accessibility sizes, reduce motion, high contrast, etc.).
|
||||
/// Override in subclasses instead of overriding setUp().
|
||||
/// Extra launch arguments (accessibility sizes, reduce motion, etc.).
|
||||
var extraLaunchArguments: [String] { [] }
|
||||
|
||||
// MARK: - Lifecycle
|
||||
@@ -65,18 +66,10 @@ class BaseUITestCase: XCTestCase {
|
||||
private func buildLaunchArguments(resetState: Bool) -> [String] {
|
||||
var args = ["--ui-testing", "--disable-animations"]
|
||||
args.append(contentsOf: localeArguments)
|
||||
if resetState {
|
||||
args.append("--reset-state")
|
||||
}
|
||||
if bypassSubscription {
|
||||
args.append("--bypass-subscription")
|
||||
}
|
||||
if skipOnboarding {
|
||||
args.append("--skip-onboarding")
|
||||
}
|
||||
if expireTrial {
|
||||
args.append("--expire-trial")
|
||||
}
|
||||
if resetState { args.append("--reset-state") }
|
||||
if bypassSubscription { args.append("--bypass-subscription") }
|
||||
if skipOnboarding { args.append("--skip-onboarding") }
|
||||
if expireTrial { args.append("--expire-trial") }
|
||||
args.append(contentsOf: extraLaunchArguments)
|
||||
return args
|
||||
}
|
||||
@@ -84,9 +77,7 @@ class BaseUITestCase: XCTestCase {
|
||||
private func buildLaunchEnvironment() -> [String: String] {
|
||||
var env = [String: String]()
|
||||
env["UI_TEST_SESSION_ID"] = testSessionID
|
||||
if let fixture = seedFixture {
|
||||
env["UI_TEST_FIXTURE"] = fixture
|
||||
}
|
||||
if let fixture = seedFixture { env["UI_TEST_FIXTURE"] = fixture }
|
||||
return env
|
||||
}
|
||||
|
||||
@@ -99,7 +90,7 @@ class BaseUITestCase: XCTestCase {
|
||||
add(screenshot)
|
||||
}
|
||||
|
||||
// MARK: - Shared Test Utilities
|
||||
// MARK: - Launch Helpers
|
||||
|
||||
@discardableResult
|
||||
func launchApp(resetState: Bool) -> XCUIApplication {
|
||||
@@ -110,8 +101,7 @@ class BaseUITestCase: XCTestCase {
|
||||
return application
|
||||
}
|
||||
|
||||
/// Relaunch the app with custom bypass setting, preserving the session ID.
|
||||
/// Use when a test needs to toggle subscription bypass mid-test.
|
||||
/// Relaunch with a different bypass setting, preserving session ID.
|
||||
@discardableResult
|
||||
func relaunchApp(resetState: Bool, bypassSubscription overrideBypass: Bool) -> XCUIApplication {
|
||||
app.terminate()
|
||||
@@ -137,10 +127,4 @@ class BaseUITestCase: XCTestCase {
|
||||
app = relaunched
|
||||
return relaunched
|
||||
}
|
||||
|
||||
func assertDayContentVisible(timeout: TimeInterval = 8, file: StaticString = #file, line: UInt = #line) {
|
||||
let hasEntry = app.firstEntryRow.waitForExistence(timeout: timeout)
|
||||
let hasMoodHeader = app.element(UITestID.Day.moodHeader).waitForExistence(timeout: 2)
|
||||
XCTAssertTrue(hasEntry || hasMoodHeader, "Day view should show entry list or mood header", file: file, line: line)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user