smithery.ai

xctest

XCTest and XCUITest patterns for iOS/watchOS testing. Use when writing unit tests, UI tests, or debugging test failures.

First seen Apr 17, 2026

Installation

$ npx skills add https://smithery.ai

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery.ai · top by installs.

npx skills add https://smithery.ai

Browse all from smithery.ai

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 3,360 B
  • docs SUMMARY.md 134 B

History

  1. First seen on skills.sh
  2. First recorded snapshot · 1 installs

SKILL.md

XCTest Best Practices

Test Structure

Arrange-Act-Assert Pattern

func testAddItemToList_incrementsCount() {
    // Arrange
    let list = List(name: "Groceries")
    let initialCount = list.items.count

    // Act
    list.addItem(Item(text: "Milk"))

    // Assert
    XCTAssertEqual(list.items.count, initialCount + 1)
}

Naming Convention

Format: test<MethodOrBehavior><Scenario><ExpectedOutcome>

  • Good: testLoginwithInvalidCredentialsshowsErrorMessage
  • Bad: testLogin1, testLoginStuff

Assertions

Use Specific Assertions

// GOOD: Clear failure messages
XCTAssertEqual(items.count, 3, "Expected 3 items after adding")
XCTAssertTrue(list.isEmpty)
XCTAssertNil(error)
XCTAssertThrowsError(try service.save(invalidItem))

// Use XCTUnwrap for safe optionals
let item = try XCTUnwrap(list.items.first, "List should have item")
XCTAssertEqual(item.text, "Milk")

// BAD: Generic with poor failure messages
XCTAssert(items.count == 3)  // "XCTAssertTrue failed"

Async Testing

Modern async/await

func testFetchItems_returnsItems() async throws {
    let mockAPI = MockAPI()
    mockAPI.itemsToReturn = [Item(text: "Test")]
    let service = ItemService(api: mockAPI)

    let items = try await service.fetchItems()

    XCTAssertEqual(items.count, 1)
}

Expectations for callbacks

func testAsyncOperation_completesWithSuccess() {
    let expectation = expectation(description: "completes")

    service.performAsync { result in
        XCTAssertTrue(result.isSuccess)
        expectation.fulfill()
    }

    wait(for: [expectation], timeout: 5.0)
}

UI Testing

Accessibility Identifiers

// In production code
Button("Add Item")
    .accessibilityIdentifier("addItemButton")

// In UI test
let addButton = app.buttons["addItemButton"]
XCTAssertTrue(addButton.exists)
addButton.tap()

Wait for Elements

// GOOD: Wait with timeout
let element = app.staticTexts["Welcome"]
XCTAssertTrue(element.waitForExistence(timeout: 10))

// BAD: Fixed delay
sleep(3)  // Flaky and slow

Antipatterns

Multiple behaviors in one test

// BAD: Tests too many things
func testListOperations() {
    list.addItem(item1)
    XCTAssertEqual(list.count, 1)
    list.addItem(item2)
    XCTAssertEqual(list.count, 2)
    list.removeItem(item1)
    XCTAssertEqual(list.count, 1)
}

// GOOD: Focused tests
func testAddItem_incrementsCount() { ... }
func testRemoveItem_decrementsCount() { ... }

Force unwrapping

// BAD: Crashes on failure
let item = list.items.first!

// GOOD: Safe unwrap
let item = try XCTUnwrap(list.items.first)

No timeouts

// BAD: Can hang forever
wait(for: [exp], timeout: .infinity)

// GOOD: Reasonable timeout
wait(for: [exp], timeout: 30.0)

Deterministic Test Data

// GOOD: Fixed, reproducible data
let testItem = Item(
    id: UUID(uuidString: "12345678-1234-1234-1234-123456789ABC")!,
    text: "Test Item",
    createdAt: Date(timeIntervalSince1970: 1700000000)
)

// BAD: Random data
let testItem = Item(
    id: UUID(),  // Different every run
    text: "Item \(Int.random(in: 1...100))"
)