Native Automation Skill
Philosophy: Use Apple's first-party tools (XCTest, XCUITest, Instruments) as the source of truth for quality.
Capabilities
- 1. Unit Testing Logic: fast, isolated logic verification.
- UI Testing: End-to-end user flow verification.
- Snapshot Testing: Visual regression testing.
- Performance Testing: XCTMetric verification.
- Accessibility Testing: Automated audit via XCUITest.
- Hero Flow Verification: Integrated critical path testing (Input -> Process -> Connect).
Usage
1. Execute Tests via Script
Always use the wrapper script to ensure correct scheme and destination settings.
CODEBLOCK0
Modes:
- -
unit: Run unit tests only (Logic layer). - INLINECODE1 : Run UI tests only (Interaction layer).
- INLINECODE2 : Run unit + critical UI paths.
- INLINECODE3 : Run ALL tests (including performance and snapshots).
2. Writing Tests
- - Unit: Inherit from
XCTestCase. Use XCTAssert.... - UI: Inherit from
XCTestCase. Use XCUIApplication. - Performance: Use
measure(metrics:options:block:).
Best Practices
- - Isolation: Reset state before each UI test (
app.launchArguments += ["-reset"]). - Accessibility: Use
app.buttons["identifier"] over static texts. - Concurrency: Use
XCTestExpectation for async code.
原生自动化技能
理念:将苹果第一方工具(XCTest、XCUITest、Instruments)作为质量保障的权威来源。
能力
- 1. 单元测试逻辑:快速、独立的逻辑验证。
- UI测试:端到端的用户流程验证。
- 快照测试:视觉回归测试。
- 性能测试:XCTMetric验证。
- 无障碍测试:通过XCUITest自动审计。
- 核心流程验证:集成的关键路径测试(输入 -> 处理 -> 连接)。
使用方法
1. 通过脚本执行测试
始终使用包装脚本以确保正确的方案和目标设置。
bash
./tools/runnativetests.sh [模式]
模式:
- - unit:仅运行单元测试(逻辑层)。
- ui:仅运行UI测试(交互层)。
- fast:运行单元测试 + 关键UI路径。
- full:运行所有测试(包括性能和快照)。
2. 编写测试
- - 单元测试:继承自XCTestCase。使用XCTAssert...。
- UI测试:继承自XCTestCase。使用XCUIApplication。
- 性能测试:使用measure(metrics:options:block:)。
最佳实践
- - 隔离性:在每个UI测试前重置状态(app.launchArguments += [-reset])。
- 无障碍:优先使用app.buttons[identifier]而非静态文本。
- 并发性:对异步代码使用XCTestExpectation。