Skillshub swift-testing
Standards for XCTest, Async Tests, and Test Organization. Use when writing XCTest cases, async tests, or organizing test suites in Swift. (triggers: **/*Tests.swift, XCTestCase, XCTestExpectation, XCTAssert)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/swift-testing" ~/.claude/skills/comeonoliver-skillshub-swift-testing && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/swift-testing/SKILL.mdsource content
Swift Testing Standards
Priority: P0
Implementation Guidelines
XCTest Framework
- Standard Naming: Test functions must be prefixed by 'test' (e.g.,
).func testUserLoginSuccessful() - Setup/Teardown: Use
andsetUpWithError()
for environment management.tearDownWithError() - Assertions: Use specific assertions:
,XCTAssertEqual
,XCTAssertNil
, etc.XCTAssertTrue
Async Testing
- Async/Await: Mark test methods as
and useasync throws
directly inside them.try await - Expectations: Use
for callback-based async logic. CallXCTestExpectation
thenexpectation
when done; thenfulfill()
to block.wait(for: [exp], timeout: 2.0) - Timeout: Always set reasonable timeouts for expectations to avoid hanging CI.
Test Organization
- Unit Tests: Use protocols for dependencies and Inject them via constructor (e.g.,
). Focus on logic isolation using mocks/stubs.init(service: ServiceProtocol) - UI Tests: Test user flows using
and accessibility identifiers.XCUIApplication - Coverage: Aim for high coverage on critical business logic and state transitions.
Anti-Patterns
- No Thread.sleep: Use expectations or await.
- No force unwrap in tests: Use XCTUnwrap() for better failure messages.
- No assertion-free tests: A test that only runs code is not a test.