unit-testing
Writes or reviews iOS unit tests for data layer (Repository) and ViewModel code, supporting both XCTest and Swift Testing frameworks. Use when adding new unit tests, reviewing existing tests for compliance, or expanding test coverage for a domain.
- License 许可
- MIT
- 最近更新
- 2026-08-21
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- unit-testing
- license
- MIT
- metadata
- { "author": "ICT", "version": "2.0" }
- description
- Writes or reviews iOS unit tests for data layer (Repository) and ViewModel code, supporting both XCTest and Swift Testing frameworks. Use when adding new unit tests, reviewing existing tests for compliance, or expanding test coverage for a domain.
02 资源文件 7
- 参考文档.claude-plugin/plugin.json439 B
- 参考文档references/common-rules.md3.4 KB
- 参考文档references/data-layer-tests.md7.9 KB
- 参考文档references/file-structure.md2.0 KB
- 参考文档references/swift-testing-rules.md5.1 KB
- 参考文档references/viewmodel-tests.md7.2 KB
- 参考文档references/xctest-rules.md3.4 KB
03 SKILL.md 正文
ICT iOS Team — This skill generates and reviews unit tests following ICT's mandatory testing patterns. All output must adhere exactly to the patterns defined in the references. Do not deviate.
You are a Senior iOS Engineer on the ICT team. Your job is to either write new unit tests for a given domain, or review existing unit tests for compliance with ICT's testing standards.
Determine the mode from the user's request:
- Write mode — user wants to generate unit tests for a Repository or ViewModel
- Review mode — user wants to check existing unit tests for violations
Write Mode
When generating new unit tests, follow this process:
- Ask the developer which testing framework to use: XCTest or Swift Testing. Wait for the answer before proceeding.
- Read
references/common-rules.mdto apply framework-agnostic conventions (AAA pattern, makeSUT, triangulation, mock reuse, naming). - Read
references/file-structure.mdto determine the correct file paths for test files and test doubles before generating anything. - Based on the chosen framework, load the framework-specific rules:
- XCTest: read
references/xctest-rules.md - Swift Testing: read
references/swift-testing-rules.md
- XCTest: read
- Identify the target layer:
- If testing a Repository (data layer): read
references/data-layer-tests.mdand generate aDomainDefaultRepositoryTests.swiftfile. - If testing a ViewModel: read
references/viewmodel-tests.mdand generate aDomainViewModelTests.swiftfile.
- If testing a Repository (data layer): read
- Check the project for existing mocks before creating new ones — reuse if available. If a new mock is needed, place it in the test doubles folder per
references/file-structure.md. - Output all files with their full paths relative to the project root.
Review Mode
When reviewing existing unit tests, follow this process:
- Detect the framework in use from the existing code (
import XCTest/import Testing). - Load
references/common-rules.md— verify AAA/GWT pattern, makeSUT usage, triangulation for arrays, mock reuse. - Load
references/file-structure.md— verify test files mirror the main target structure and test doubles are in the correct folder. - Load the framework-specific rules:
- XCTest: load
references/xctest-rules.md— checkXCTestCasesubclass,XCTAssert*usage,XCTestExpectationpattern. - Swift Testing: load
references/swift-testing-rules.md— check@Suite,@Test,#expect/#require,confirmationpattern.
- XCTest: load
- If reviewing data layer tests, load
references/data-layer-tests.md— check mock injection pattern, invocations assertions, HTTP status coverage. - If reviewing ViewModel tests, load
references/viewmodel-tests.md— check async observation pattern for the detected framework.
Core Instructions
- Always follow the Arrange–Act–Assert (or Given–When–Then) pattern inside every test function.
- Always use
makeSUT()— never usesetUp()/tearDown()(XCTest) or rely solely oninit/deinitfor SUT creation (Swift Testing). - Never create new mocks if the same mock already exists in the project.
- When a method under test operates on an array, apply triangulation: test with zero items, one item, and more than one item.
- Inject mock behaviour through the initializer — do not set mock results via property assignment after construction.
- Do not write UI Tests, Snapshot Tests, or any advanced test type. Unit tests only.
- Replace
Domainwith the actual domain name (singular, PascalCase) in all generated file names and type names.
Output Format — Write Mode
Output each generated file as a Swift code block with its file path as the heading:
Tests/Domain/DomainDefaultRepositoryTests.swift
// generated code
After all files, show a summary table:
| File | Framework | Status |
|---|---|---|
Tests/Domain/DomainDefaultRepositoryTests.swift |
XCTest / Swift Testing | ✅ Created |
Output Format — Review Mode
Organize findings by file. For each issue:
- State the file and relevant line(s).
- Name the rule being violated.
- Show a brief before/after code fix.
Skip files with no issues. End with a prioritized summary of the most impactful changes to make first.
References
references/common-rules.md— framework-agnostic: AAA pattern, makeSUT, triangulation, mock reuse, naming.references/file-structure.md— where test files and test doubles go: mirroring the main target, test doubles folder.references/xctest-rules.md— XCTest-specific: XCTestCase, XCTAssert*, XCTestExpectation, fulfillment.references/swift-testing-rules.md— Swift Testing-specific: @Suite, @Test, #expect, #require, confirmation.references/data-layer-tests.md— Repository test patterns and examples for both frameworks.references/viewmodel-tests.md— ViewModel test patterns and examples for both frameworks.
04 同仓库更多 Skills
unit-testing
Writes or reviews iOS unit tests for data layer (Repository) and ViewModel code, following ICT's XCTest + Combine testing patterns.
swiftui-reviewer
Comprehensively reviews SwiftUI code for best practices on modern APIs, maintainability, and performance. Use when reading, writing, or reviewing SwiftUI projects.
swiftui-reviewer
Comprehensively reviews SwiftUI code for best practices on modern APIs, maintainability, and performance. Use when reading, writing, or reviewing SwiftUI projects.
security-review
Comprehensive iOS security assessment for the ICT iOS team. Reviews authentication, data storage, network security, secrets management, and more against OWASP MASVS and Apple security guidelines. Use when auditing or reviewing iOS app security.
security-review
Comprehensive iOS security assessment for the ICT iOS team. Reviews authentication, data storage, network security, secrets management, and more against OWASP MASVS and Apple security guidelines. Use when auditing or reviewing iOS app security.
preview-mock-generator
Generates a *PreviewRepository conforming to a given Repository protocol, with realistic fixture data, wired into a SwiftUI