Browse Questions
  • They test different layers of the app and run at different speeds.
  • To create a custom Xcode File Template from scratch, create a .xctemplate directory inside ~/Library/Developer/Xcode/Templates/File Templates/<Category>/, add a TemplateInfo.plist declaring the…
  • Result<Success, Failure> is an enum with .success and .failure cases.
  • Both static and class define type-level properties and methods, but static members cannot be overridden by subclasses (final), whereas class members allow dynamic dispatch and can be overridden.

Answer: They test different layers of the app and run at different speeds.

Unit TestsUI Tests
WhatIsolated logicFull app user flows
SpeedVery fast (ms)Slow (seconds)
FrameworkXCTestXCUITest
DependenciesMockedReal app running
FlakinessLowHigher

Code Example:

// Unit test — tests a function in isolation
class PriceFormatterTests: XCTestCase {
    func test_formatPrice_returnsCurrencyString() {
        let formatter = PriceFormatter()
        let result = formatter.format(9.99)
        XCTAssertEqual(result, "$9.99")
    }
}

// UI test — launches the app and interacts with it
class CheckoutUITests: XCTestCase {
    let app = XCUIApplication()

    override func setUp() { app.launch() }

    func test_addToCart_showsCartBadge() {
        app.buttons["Add to Cart"].tap()
        XCTAssertTrue(app.staticTexts["1"].exists)
    }
}