AgentSkillsCN

watchos-testing

当用户就NixOS的安装、“nixos-rebuild”、“disko”、“hardware-configuration.nix”、“生成回滚”,或在NixOS中遭遇各类错误时,本技能将为您提供精准指导。若涉及nix-darwin,则应使用“管理macOS”的相关技能;若遇到Flake相关问题,则可参考“理解Nix”的相关技能。

SKILL.md
--- frontmatter
name: watchos-testing
description: watchOS and iOS testing expert for unit tests, UI tests, and test-driven development. Use when working with XCTest, testing SwiftUI views, testing WatchKit components, or implementing test strategies for watch apps.
allowed-tools: Read, Grep, Glob, Bash(xcodebuild:*), Bash(xcrun simctl:*)

watchOS Testing Expert

Instructions

When helping with watchOS/iOS testing:

  1. Analyze existing test coverage
  2. Identify untested code paths
  3. Generate comprehensive test cases
  4. Use XCTest and Swift Testing frameworks appropriately

watchOS-Specific Testing

Challenges

  • Limited UI testing on watchOS
  • Notification testing requires mocking
  • WebSocket testing needs stub servers
  • Complication testing is complex

Approaches

  • Use dependency injection for testability
  • Mock network services (WebSocket, APNs)
  • Test view models separately from views
  • Use @testable import for internal access

Test Patterns

Unit Test Template

swift
import XCTest
@testable import ClaudeWatch

final class WatchServiceTests: XCTestCase {
    var sut: WatchService!

    override func setUp() {
        super.setUp()
        sut = WatchService()
    }

    override func tearDown() {
        sut = nil
        super.tearDown()
    }

    func testExample() {
        // Given
        // When
        // Then
        XCTAssertNotNil(sut)
    }
}

Async Test Pattern

swift
func testAsyncOperation() async throws {
    // Given
    let expectation = XCTestExpectation(description: "Async operation")

    // When
    let result = try await sut.performAsyncAction()

    // Then
    XCTAssertTrue(result)
}

Best Practices

  • Test behavior, not implementation details
  • Use dependency injection for all external services
  • Mock WebSocket connections for network tests
  • Target 80%+ coverage for critical paths (Services, ViewModels)
  • Use @MainActor annotation for UI-related tests