Smart router to testing patterns and practices. Use when writing unit tests, creating mocks, testing edge cases, or working with Swift Testing and XCTest frameworks.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
tests-developer
description
Smart router to testing patterns and practices. Use when writing unit tests, creating mocks, testing edge cases, or working with Swift Testing and XCTest frameworks.
Tests Developer Skill
Smart router to testing patterns and practices. Writing unit tests, creating mocks, test organization.
When to Use This Skill
This skill activates when working with:
Writing unit tests
Creating test mocks
Testing edge cases
Test-driven development (TDD)
Test refactoring and updates
Swift Testing framework usage
XCTest framework usage
Quick Reference
Critical Rules
✅ Use Swift Testing framework (import Testing, @Test, @Suite) for NEW tests
@Suite(.serialized) // Required for DI setupstructMyFeatureTests {
privatelet mockService: MyServiceMockinit() {
let mockService =MyServiceMock()
Container.shared.myService.register { mockService }
self.mockService = mockService
}
@TestfunctestWithMockedDependency() {
mockService.expectedResult ="test"let sut =MyFeature()
let result = sut.doWork()
#expect(result =="test")
}
}
4. Testing Protocols (Make Methods Internal)
Problem: Private methods can't be tested
Solution: Use internal access and test via protocol
// Production code - SetContentViewDataBuilder.swiftfinalclassSetContentViewDataBuilder: SetContentViewDataBuilderProtocol {
// ✅ Internal for testing (not private)funcbuildChatPreview(
objectId: String,
spaceView: SpaceView?,
chatPreviewsDict: [String: ChatMessagePreview]
) -> MessagePreviewModel? {
// Implementation
}
}
// Test code@TestfunctestBuildChatPreview_EmptyDict_ReturnsNil() {
let result = builder.buildChatPreview(
objectId: "test",
spaceView: nil,
chatPreviewsDict: [:]
)
#expect(result ==nil)
}
5. Dictionary Conversion Testing
Performance validation:
@TestfunctestDictionaryConversion_EmptyArray() {
let items: [Item] = []
let dict =Dictionary(uniqueKeysWithValues: items.map { ($0.id, $0) })
#expect(dict.isEmpty)
}
@TestfunctestDictionaryConversion_MultipleItems() {
let items = (0..<10).map { Item(id: "item\($0)") }
let dict =Dictionary(uniqueKeysWithValues: items.map { ($0.id, $0) })
#expect(dict.count ==10)
for i in0..<10 {
#expect(dict["item\(i)"] !=nil)
}
}
@TestfunctestDictionaryLookup_O1Performance() {
let items = (0..<100).map { Item(id: "item\($0)") }
let dict =Dictionary(uniqueKeysWithValues: items.map { ($0.id, $0) })
let result = dict["item50"]
#expect(result !=nil)
#expect(result?.id =="item50")
}
6. Testing with Dates
@TestfunctestDateFormatting() {
let date =Date(timeIntervalSince1970: 1700000000)
let result = formatter.format(date)
#expect(result.isEmpty ==false)
}
@TestfunctestDateComparison() {
let now =Date()
let future = now.addingTimeInterval(3600)
#expect(future > now)
}
7. Testing Protobuf Models
ChatState example:
@TestfunctestChatStateCounters() {
var chatState =ChatState()
var messagesState =ChatState.UnreadState()
messagesState.counter =5
chatState.messages = messagesState
var mentionsState =ChatState.UnreadState()
mentionsState.counter =2
chatState.mentions = mentionsState
#expect(chatState.messages.counter ==5)
#expect(chatState.mentions.counter ==2)
}
@TestfunctestParseValidInput() {
let result = parser.parse("valid input")
#expect(result !=nil)
}
@TestfunctestParseInvalidInput_ReturnsNil() {
let result = parser.parse("")
#expect(result ==nil)
}
Pattern 4: Counter/State Testing
@TestfunctestCountersPropagation() {
var model =Model()
model.state = createState(messages: 5, mentions: 2)
#expect(model.unreadCounter ==5)
#expect(model.mentionCounter ==2)
}
Test File Examples
Example 1: SetContentViewDataBuilderTests.swift
Full working example:AnyTypeTests/Services/SetContentViewDataBuilderTests.swift
Tests builder methods
Creates mock helpers
Tests edge cases (nil, empty, truncation)
Tests counter propagation
Tests dictionary conversion performance
Example 2: ChatMessageLimitsTests.swift
Full working example:AnyTypeTests/Services/ChatMessageLimitsTests.swift
Uses @Suite(.serialized) for DI setup
Mocks date provider via Factory DI
Tests rate limiting logic
Tests time-based conditions
Related Documentation
CLAUDE.md: Project guidelines, no comments rule, testing requirements
IOS_DEVELOPMENT_GUIDE.md: Swift patterns, MVVM architecture
.claude/CODE_REVIEW_GUIDE.md: Review standards including test updates
Navigation: This is a smart router. For comprehensive testing guidelines and architecture patterns, refer to IOS_DEVELOPMENT_GUIDE.md.
Quick help: Just ask "How do I test X?" or "Create tests for Y feature"